package org.oransc.ric.portal.dashboard.controller;
import java.lang.invoke.MethodHandles;
+import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.oransc.ric.a1med.client.api.A1MediatorApi;
+import org.oransc.ric.a1med.client.model.PolicyTypeSchema;
import org.oransc.ric.portal.dashboard.DashboardApplication;
import org.oransc.ric.portal.dashboard.DashboardConstants;
import org.oransc.ric.portal.dashboard.config.A1MediatorApiBuilder;
private static final Logger logger = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
- /** This path lacks the RIC instance pattern */
+ // Publish paths in constants so tests are easy to write
public static final String CONTROLLER_PATH = DashboardConstants.ENDPOINT_PREFIX + "/a1-p";
- // Path parameters
- public static final String PP_POLICIES = "policies";
- // The get and put methods use the same path
- private static final String POLICY_METHOD_PATH = /* controller path + */ DashboardConstants.RIC_INSTANCE_KEY + "/{"
- + DashboardConstants.RIC_INSTANCE_KEY + "}/" + PP_POLICIES + "/{" + PP_POLICIES + "}";
+ public static final String PP_TYPE_ID = "poltype";
+ public static final String PP_INST_ID = "polinst";
+ // The get- and put-instance methods use the same path
+ private static final String POLICY_INSTANCE_METHOD_PATH = /* controller path + */ DashboardConstants.RIC_INSTANCE_KEY
+ + "/{" + DashboardConstants.RIC_INSTANCE_KEY + "}/" + PP_TYPE_ID + "/{" + PP_TYPE_ID + "}/" + PP_INST_ID
+ + "/{" + PP_INST_ID + "}";
// Populated by the autowired constructor
private final A1MediatorApiBuilder a1MediatorClientBuilder;
return new SuccessTransport(200, DashboardApplication.getImplementationVersion(A1MediatorApi.class));
}
- @ApiOperation(value = "Gets the specified policy from the A1 Mediator")
- @GetMapping(POLICY_METHOD_PATH)
+ @ApiOperation(value = "Gets the registered policy type IDs from the A1 Mediator", response = Integer.class, responseContainer = "List")
+ @GetMapping(DashboardConstants.RIC_INSTANCE_KEY + "/{" + DashboardConstants.RIC_INSTANCE_KEY + "}/" + PP_TYPE_ID)
@Secured({ DashboardConstants.ROLE_ADMIN, DashboardConstants.ROLE_STANDARD })
- public Object getPolicy(@PathVariable(DashboardConstants.RIC_INSTANCE_KEY) String instanceKey,
- @PathVariable(PP_POLICIES) String policyName) {
- logger.debug("getPolicy instance {} policy {}", instanceKey, policyName);
- return a1MediatorClientBuilder.getA1MediatorApi(instanceKey).a1ControllerGetHandler(policyName);
+ public List<Integer> getAllPolicyTypes(@PathVariable(DashboardConstants.RIC_INSTANCE_KEY) String instanceKey) {
+ logger.debug("getAllPolicyTypes: instance {}", instanceKey);
+ Object result = a1MediatorClientBuilder.getA1MediatorApi(instanceKey).a1ControllerGetAllPolicyTypes();
+ @SuppressWarnings("unchecked")
+ List<Integer> result2 = (List<Integer>) result;
+ return result2;
}
- @ApiOperation(value = "Puts the specified policy to the A1 Mediator")
- @PutMapping(POLICY_METHOD_PATH)
+ @ApiOperation(value = "Gets the specified policy type from the A1 Mediator", response = PolicyTypeSchema.class)
+ @GetMapping(DashboardConstants.RIC_INSTANCE_KEY + "/{" + DashboardConstants.RIC_INSTANCE_KEY + "}/" + PP_TYPE_ID
+ + "/{" + PP_TYPE_ID + "}")
+ @Secured({ DashboardConstants.ROLE_ADMIN, DashboardConstants.ROLE_STANDARD })
+ public PolicyTypeSchema getPolicyType(@PathVariable(DashboardConstants.RIC_INSTANCE_KEY) String instanceKey,
+ @PathVariable(PP_TYPE_ID) Integer policyTypeId) {
+ logger.debug("getPolicyType: instance {} typeId {}", instanceKey, policyTypeId);
+ return a1MediatorClientBuilder.getA1MediatorApi(instanceKey).a1ControllerGetPolicyType(policyTypeId);
+ }
+
+ @ApiOperation(value = "Gets the specified policy instance from the A1 Mediator")
+ @GetMapping(POLICY_INSTANCE_METHOD_PATH)
+ @Secured({ DashboardConstants.ROLE_ADMIN, DashboardConstants.ROLE_STANDARD })
+ public Object getPolicyInstance(@PathVariable(DashboardConstants.RIC_INSTANCE_KEY) String instanceKey,
+ @PathVariable(PP_TYPE_ID) Integer policyTypeId, //
+ @PathVariable(PP_INST_ID) String policyInstanceId) {
+ logger.debug("getPolicyInstance: instance {} typeId {} instanceId {}", instanceKey, policyTypeId,
+ policyInstanceId);
+ return a1MediatorClientBuilder.getA1MediatorApi(instanceKey).a1ControllerGetPolicyInstance(policyTypeId,
+ policyInstanceId);
+ }
+
+ @ApiOperation(value = "Creates or replaces the specified policy instance at the A1 Mediator")
+ @PutMapping(POLICY_INSTANCE_METHOD_PATH)
@Secured({ DashboardConstants.ROLE_ADMIN })
- public void putPolicy(@PathVariable(DashboardConstants.RIC_INSTANCE_KEY) String instanceKey,
- @PathVariable(PP_POLICIES) String policyName, @ApiParam(value = "Policy body") @RequestBody String policy, //
+ public void createPolicyInstance(@PathVariable(DashboardConstants.RIC_INSTANCE_KEY) String instanceKey,
+ @PathVariable(PP_TYPE_ID) Integer policyTypeId, //
+ @PathVariable(PP_INST_ID) String policyInstanceId,
+ @ApiParam(value = "Policy body") @RequestBody String policyBody, //
HttpServletResponse response) {
- logger.debug("putPolicy instance {} name {} value {}", instanceKey, policyName, policy);
+ logger.debug("createPolicyInstance: instance {} typeId {} instanceId {}", instanceKey, policyTypeId,
+ policyInstanceId);
A1MediatorApi api = a1MediatorClientBuilder.getA1MediatorApi(instanceKey);
- api.a1ControllerPutHandler(policyName, policy);
+ api.a1ControllerCreateOrReplacePolicyInstance(policyTypeId, policyInstanceId, policyBody);
response.setStatus(api.getApiClient().getStatusCode().value());
}