diff options
author | FrancescoFioraEst <francesco.fiora@est.tech> | 2022-11-14 10:49:34 +0000 |
---|---|---|
committer | Francesco Fiora <francesco.fiora@est.tech> | 2022-11-14 14:45:18 +0000 |
commit | c32d7926409b4c164e2a5097e7ba1bc4d766bd5b (patch) | |
tree | c0beffd2b72a7eb06db7eb0f9e3c687c24d1ded7 /runtime-acm/src | |
parent | cfa51e6177b801fcf456390cdaea520b6378de39 (diff) |
Remove redundant endpoints in ACM
Remove redundant endpoints in ACM
not present in the new generated Api code.
Issue-ID: POLICY-4453
Change-Id: I4b843c2637e934f8a29f71d8031bdfe903ff20dc
Signed-off-by: FrancescoFioraEst <francesco.fiora@est.tech>
Diffstat (limited to 'runtime-acm/src')
7 files changed, 0 insertions, 1199 deletions
diff --git a/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/commissioning/CommissioningProvider.java b/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/commissioning/CommissioningProvider.java index 0a78c54de..55d7b0c13 100644 --- a/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/commissioning/CommissioningProvider.java +++ b/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/commissioning/CommissioningProvider.java @@ -44,7 +44,6 @@ import org.onap.policy.models.base.PfModelException; import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier; import org.onap.policy.models.tosca.authorative.concepts.ToscaNodeTemplate; import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate; -import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplates; import org.onap.policy.models.tosca.authorative.concepts.ToscaTypedEntityFilter; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -206,44 +205,6 @@ public class CommissioningProvider { } /** - * Get node templates with common properties added. - * - * @param name the name of the definition to use, null for all definitions - * @param version the version of the definition to use, null for all definitions - * @param instanceName automation composition name - * @param common boolean indicating common or instance properties to be used - * @return the nodes templates with common or instance properties - * @throws PfModelException on errors getting common or instance properties from node_templates - */ - @Transactional(readOnly = true) - public Map<String, ToscaNodeTemplate> getNodeTemplatesWithCommonOrInstanceProperties( - final String name, final String version, final String instanceName, final boolean common) - throws PfModelException { - - if (common && verifyIfInstancePropertiesExists()) { - throw new PfModelException(Status.BAD_REQUEST, - "Cannot create or edit common properties, delete all the instantiations first"); - } - - var serviceTemplateList = serviceTemplateProvider.getServiceTemplateList(name, version); - - if (serviceTemplateList.isEmpty()) { - throw new PfModelException(Status.BAD_REQUEST, - "Tosca service template has to be commissioned before saving instance properties"); - } - - var commonOrInstanceNodeTypeProps = - serviceTemplateProvider.getCommonOrInstancePropertiesFromNodeTypes(common, serviceTemplateList.get(0)); - - var serviceTemplates = new ToscaServiceTemplates(); - serviceTemplates.setServiceTemplates(filterToscaNodeTemplateInstance(serviceTemplateList, instanceName)); - - return serviceTemplateProvider.getDerivedCommonOrInstanceNodeTemplates( - serviceTemplates.getServiceTemplates().get(0).getToscaTopologyTemplate().getNodeTemplates(), - commonOrInstanceNodeTypeProps); - } - - /** * Get the requested automation composition definitions. * * @param name the name of the definition to get, null for all definitions diff --git a/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/instantiation/AutomationCompositionInstantiationProvider.java b/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/instantiation/AutomationCompositionInstantiationProvider.java index 98b59aed7..18fd1f938 100644 --- a/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/instantiation/AutomationCompositionInstantiationProvider.java +++ b/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/instantiation/AutomationCompositionInstantiationProvider.java @@ -21,20 +21,12 @@ package org.onap.policy.clamp.acm.runtime.instantiation; -import com.google.gson.Gson; -import com.google.gson.internal.LinkedTreeMap; -import com.google.gson.reflect.TypeToken; -import java.lang.reflect.Type; import java.util.ArrayList; -import java.util.Collection; -import java.util.HashMap; import java.util.List; import java.util.Map; -import java.util.UUID; import java.util.function.Function; import java.util.function.UnaryOperator; import java.util.stream.Collectors; -import java.util.stream.Stream; import javax.ws.rs.core.Response; import javax.ws.rs.core.Response.Status; import lombok.AllArgsConstructor; @@ -43,15 +35,9 @@ import org.onap.policy.clamp.acm.runtime.supervision.SupervisionHandler; import org.onap.policy.clamp.common.acm.exception.AutomationCompositionException; import org.onap.policy.clamp.models.acm.concepts.AutomationComposition; import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionElement; -import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionOrderedState; import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionState; import org.onap.policy.clamp.models.acm.concepts.AutomationCompositions; import org.onap.policy.clamp.models.acm.concepts.Participant; -import org.onap.policy.clamp.models.acm.messages.rest.GenericNameVersion; -import org.onap.policy.clamp.models.acm.messages.rest.instantiation.AutomationCompositionOrderStateResponse; -import org.onap.policy.clamp.models.acm.messages.rest.instantiation.AutomationCompositionPrimed; -import org.onap.policy.clamp.models.acm.messages.rest.instantiation.AutomationCompositionPrimedResponse; -import org.onap.policy.clamp.models.acm.messages.rest.instantiation.InstancePropertiesResponse; import org.onap.policy.clamp.models.acm.messages.rest.instantiation.InstantiationCommand; import org.onap.policy.clamp.models.acm.messages.rest.instantiation.InstantiationResponse; import org.onap.policy.clamp.models.acm.persistence.provider.AutomationCompositionProvider; @@ -62,9 +48,7 @@ import org.onap.policy.common.parameters.ValidationResult; import org.onap.policy.common.parameters.ValidationStatus; import org.onap.policy.models.base.PfModelException; import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier; -import org.onap.policy.models.tosca.authorative.concepts.ToscaNameVersion; import org.onap.policy.models.tosca.authorative.concepts.ToscaNodeTemplate; -import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -75,15 +59,7 @@ import org.springframework.transaction.annotation.Transactional; @Transactional @AllArgsConstructor public class AutomationCompositionInstantiationProvider { - private static final String AUTOMATION_COMPOSITION_NODE_TYPE = "org.onap.policy.clamp.acm.AutomationComposition"; private static final String AUTOMATION_COMPOSITION_NODE_ELEMENT_TYPE = "AutomationCompositionElement"; - private static final String PARTICIPANT_ID_PROPERTY_KEY = "participant_id"; - private static final String PARTICIPANT_TYPE_PROPERTY_KEY = "participantType"; - private static final String AC_ELEMENT_NAME = "name"; - private static final String AC_ELEMENT_VERSION = "version"; - private static final String HYPHEN = "-"; - - private static final Gson GSON = new Gson(); private final AutomationCompositionProvider automationCompositionProvider; private final CommissioningProvider commissioningProvider; @@ -92,145 +68,6 @@ public class AutomationCompositionInstantiationProvider { private static final String ENTRY = "entry "; /** - * Creates Instance Properties and automation composition. - * - * @param serviceTemplate the service template - * @return the result of the instantiation operation - * @throws PfModelException on creation errors - */ - public InstancePropertiesResponse createInstanceProperties(ToscaServiceTemplate serviceTemplate) - throws PfModelException { - - String instanceName = serviceTemplate.getName(); - AutomationComposition automationComposition = new AutomationComposition(); - Map<UUID, AutomationCompositionElement> automationCompositionElements = new HashMap<>(); - - ToscaServiceTemplate toscaServiceTemplate = commissioningProvider.getAllToscaServiceTemplate().get(0); - - Map<String, ToscaNodeTemplate> persistedNodeTemplateMap = - toscaServiceTemplate.getToscaTopologyTemplate().getNodeTemplates(); - - Map<String, ToscaNodeTemplate> nodeTemplates = deepCloneNodeTemplate(serviceTemplate); - - nodeTemplates.forEach((key, template) -> { - ToscaNodeTemplate newNodeTemplate = new ToscaNodeTemplate(); - String name = key + "-" + instanceName; - String version = template.getVersion(); - String description = template.getDescription() + " " + instanceName; - newNodeTemplate.setName(name); - newNodeTemplate.setVersion(version); - newNodeTemplate.setDescription(description); - newNodeTemplate.setProperties(new HashMap<>(template.getProperties())); - newNodeTemplate.setType(template.getType()); - newNodeTemplate.setTypeVersion(template.getTypeVersion()); - newNodeTemplate.setMetadata(template.getMetadata()); - - crateNewAutomationCompositionInstance(instanceName, automationComposition, automationCompositionElements, - template, newNodeTemplate); - - persistedNodeTemplateMap.put(name, newNodeTemplate); - }); - - AutomationCompositions automationCompositions = new AutomationCompositions(); - - serviceTemplate.getToscaTopologyTemplate().getNodeTemplates().putAll(persistedNodeTemplateMap); - - automationComposition.setElements(automationCompositionElements); - automationCompositions.getAutomationCompositionList().add(automationComposition); - - return saveInstancePropertiesAndAutomationComposition(serviceTemplate, automationCompositions); - } - - /** - * Updates Instance Properties and Automation Composition Instance. - * - * @param name the name of the automation composition to update - * @param version the version of the automation composition to update - * @param serviceTemplate tosca service template body - * @return InstancePropertiesResponse response from updating instance properties - * @throws PfModelException exception if incorrect instance name - */ - public InstancePropertiesResponse updatesInstanceProperties( - String name, String version, ToscaServiceTemplate serviceTemplate) throws PfModelException { - - if (name.length() < 3) { - throw new PfModelException(Status.BAD_REQUEST, "Instance Name cannot be empty or less than 3 characters!"); - } - - Map<String, ToscaNodeTemplate> nodeTemplates = deepCloneNodeTemplate(serviceTemplate); - Map<String, ToscaNodeTemplate> updatedNodeTemplates = new HashMap<>(); - - String instanceName = serviceTemplate.getName(); - - nodeTemplates.forEach((key, template) -> { - ToscaNodeTemplate toscaNodeTemplate = new ToscaNodeTemplate(); - - String updatedName = updateInstanceNameDescription(instanceName, name, key); - String updatedDescription = updateInstanceNameDescription( - instanceName, name, template.getDescription()); - - toscaNodeTemplate.setName(updatedName); - toscaNodeTemplate.setDescription(updatedDescription); - toscaNodeTemplate.setCapabilities(template.getCapabilities()); - toscaNodeTemplate.setRequirements(template.getRequirements()); - toscaNodeTemplate.setMetadata(template.getMetadata()); - toscaNodeTemplate.setProperties(template.getProperties()); - toscaNodeTemplate.setDerivedFrom(template.getDerivedFrom()); - toscaNodeTemplate.setVersion(template.getVersion()); - toscaNodeTemplate.setType(template.getType()); - toscaNodeTemplate.setTypeVersion(template.getTypeVersion()); - - String updatedKey = updateInstanceNameDescription(instanceName, name, key); - - updatedNodeTemplates.put(updatedKey, toscaNodeTemplate); - }); - - serviceTemplate.getToscaTopologyTemplate().getNodeTemplates().clear(); - serviceTemplate.getToscaTopologyTemplate().getNodeTemplates().putAll(updatedNodeTemplates); - - AutomationCompositions automationCompositions = updateAutomationComposition( - name, instanceName); - - deleteInstanceProperties(name, version); - - return saveInstancePropertiesAndAutomationComposition(serviceTemplate, automationCompositions); - } - - /** - * Deletes Instance Properties. - * - * @param name the name of the automation composition to delete - * @param version the version of the automation composition to delete - * @return the result of the deletion - * @throws PfModelException on deletion errors - */ - public InstantiationResponse deleteInstanceProperties(String name, String version) throws PfModelException { - - String instanceName = getInstancePropertyName(name, version); - - Map<String, ToscaNodeTemplate> filteredToscaNodeTemplateMap = new HashMap<>(); - - ToscaServiceTemplate toscaServiceTemplate = commissioningProvider.getAllToscaServiceTemplate().get(0); - - toscaServiceTemplate.getToscaTopologyTemplate().getNodeTemplates().forEach((key, nodeTemplate) -> { - if (!nodeTemplate.getName().contains(instanceName)) { - filteredToscaNodeTemplateMap.put(key, nodeTemplate); - } - }); - - List<ToscaNodeTemplate> filteredToscaNodeTemplateList = - toscaServiceTemplate.getToscaTopologyTemplate().getNodeTemplates().values().stream() - .filter(nodeTemplate -> nodeTemplate.getName().contains(instanceName)).collect(Collectors.toList()); - - InstantiationResponse response = this.deleteAutomationComposition(name, version); - - automationCompositionProvider.deleteInstanceProperties(filteredToscaNodeTemplateMap, - filteredToscaNodeTemplateList); - - return response; - } - - /** * Create automation compositions. * * @param automationCompositions the automation composition @@ -469,266 +306,4 @@ public class AutomationCompositionInstantiationProvider { return result; } - - /** - * Gets a list of automation compositions with it's ordered state. - * - * @param name the name of the automation composition to get, null for all automation compositions - * @param version the version of the automation composition to get, null for all automation compositions - * @return a list of Instantiation Command - * @throws PfModelException on errors getting automation compositions - */ - @Transactional(readOnly = true) - public AutomationCompositionOrderStateResponse getInstantiationOrderState(String name, String version) - throws PfModelException { - - List<AutomationComposition> automationCompositions = - automationCompositionProvider.getAutomationCompositions(name, version); - - var response = new AutomationCompositionOrderStateResponse(); - - automationCompositions.forEach(automationComposition -> { - var genericNameVersion = new GenericNameVersion(); - genericNameVersion.setName(automationComposition.getName()); - genericNameVersion.setVersion(automationComposition.getVersion()); - response.getAutomationCompositionIdentifierList().add(genericNameVersion); - }); - - return response; - } - - /** - * Saves Instance Properties and automation composition. - * Gets a list of automation compositions which are primed or de-primed. - * - * @param name the name of the automation composition to get, null for all automation compositions - * @param version the version of the automation composition to get, null for all automation compositions - * @return a list of Instantiation Command - * @throws PfModelException on errors getting automation compositions - */ - @Transactional(readOnly = true) - public AutomationCompositionPrimedResponse getAutomationCompositionPriming(String name, String version) - throws PfModelException { - - List<AutomationComposition> automationCompositions = - automationCompositionProvider.getAutomationCompositions(name, version); - - var response = new AutomationCompositionPrimedResponse(); - - automationCompositions.forEach(automationComposition -> { - var primed = new AutomationCompositionPrimed(); - primed.setName(automationComposition.getName()); - primed.setVersion(automationComposition.getVersion()); - primed.setPrimed(automationComposition.getPrimed()); - response.getPrimedAutomationCompositionsList().add(primed); - }); - - return response; - } - - /** - * Creates instance element name. - * - * @param serviceTemplate the service template - * @param automationCompositions a list of automation compositions - * @return the result of the instance properties and instantiation operation - * @throws PfModelException on creation errors - */ - private InstancePropertiesResponse saveInstancePropertiesAndAutomationComposition( - ToscaServiceTemplate serviceTemplate, AutomationCompositions automationCompositions) throws PfModelException { - - for (var automationComposition : automationCompositions.getAutomationCompositionList()) { - var checkAutomationCompositionOpt = - automationCompositionProvider.findAutomationComposition(automationComposition.getKey().asIdentifier()); - if (checkAutomationCompositionOpt.isPresent()) { - throw new PfModelException(Response.Status.BAD_REQUEST, "Automation composition with id " - + automationComposition.getKey().asIdentifier() + " already defined"); - } - } - Map<String, ToscaNodeTemplate> toscaSavedNodeTemplate = - automationCompositionProvider.saveInstanceProperties(serviceTemplate); - automationCompositionProvider.saveAutomationCompositions(automationCompositions.getAutomationCompositionList()); - List<ToscaConceptIdentifier> affectedAutomationCompositions = automationCompositions - .getAutomationCompositionList().stream().map(ac -> ac.getKey().asIdentifier()).collect(Collectors.toList()); - - List<ToscaConceptIdentifier> toscaAffectedProperties = toscaSavedNodeTemplate.values().stream() - .map(template -> template.getKey().asIdentifier()).collect(Collectors.toList()); - - var response = new InstancePropertiesResponse(); - response.setAffectedInstanceProperties(Stream.of(affectedAutomationCompositions, toscaAffectedProperties) - .flatMap(Collection::stream).collect(Collectors.toList())); - - return response; - } - - /** - * Crates a new automation composition instance. - * - * @param instanceName automation composition Instance name - * @param automationComposition empty automation composition - * @param automationCompositionElements new automation composition Element map - * @param template original Cloned Tosca Node Template - * @param newNodeTemplate new Tosca Node Template - */ - private void crateNewAutomationCompositionInstance(String instanceName, AutomationComposition automationComposition, - Map<UUID, AutomationCompositionElement> automationCompositionElements, ToscaNodeTemplate template, - ToscaNodeTemplate newNodeTemplate) { - if (template.getType().equals(AUTOMATION_COMPOSITION_NODE_TYPE)) { - automationComposition.setDefinition(getAutomationCompositionDefinition(newNodeTemplate)); - } - - if (template.getType().contains(AUTOMATION_COMPOSITION_NODE_ELEMENT_TYPE)) { - AutomationCompositionElement automationCompositionElement = - getAutomationCompositionElement(newNodeTemplate); - automationCompositionElements.put(automationCompositionElement.getId(), automationCompositionElement); - } - - automationComposition.setName(instanceName); - automationComposition.setVersion(template.getVersion()); - automationComposition.setDescription("Automation composition " + instanceName); - automationComposition.setState(AutomationCompositionState.UNINITIALISED); - automationComposition.setOrderedState(AutomationCompositionOrderedState.UNINITIALISED); - } - - /** - * Get's the instance property name of the automation composition. - * - * @param name the name of the automation composition to get, null for all automation compositions - * @param version the version of the automation composition to get, null for all automation compositions - * @return the instance name of the automation composition instance properties - * @throws PfModelException on errors getting automation compositions - */ - private String getInstancePropertyName(String name, String version) throws PfModelException { - List<String> toscaDefinitionsNames = - automationCompositionProvider.getAutomationCompositions(name, version).stream() - .map(AutomationComposition::getDefinition).map(ToscaNameVersion::getName).collect(Collectors.toList()); - - return toscaDefinitionsNames.stream().reduce("", (s1, s2) -> { - - if (s2.contains(HYPHEN)) { - String[] instances = s2.split(HYPHEN); - - return HYPHEN + instances[1]; - } - - return s1; - }); - } - - /** - * Retrieves automation composition Definition. - * - * @param template tosca node template - * @return automation composition definition - */ - private ToscaConceptIdentifier getAutomationCompositionDefinition(ToscaNodeTemplate template) { - ToscaConceptIdentifier definition = new ToscaConceptIdentifier(); - definition.setName(template.getName()); - definition.setVersion(template.getVersion()); - return definition; - } - - /** - * Retrieves automation composition Element. - * - * @param template tosca node template - * @return a automation composition element - */ - @SuppressWarnings("unchecked") - private AutomationCompositionElement getAutomationCompositionElement(ToscaNodeTemplate template) { - AutomationCompositionElement automationCompositionElement = new AutomationCompositionElement(); - ToscaConceptIdentifier definition = new ToscaConceptIdentifier(); - definition.setName(template.getName()); - definition.setVersion(template.getVersion()); - automationCompositionElement.setDefinition(definition); - LinkedTreeMap<String, Object> participantId = - (LinkedTreeMap<String, Object>) template.getProperties().get(PARTICIPANT_ID_PROPERTY_KEY); - if (participantId != null) { - ToscaConceptIdentifier participantIdProperty = new ToscaConceptIdentifier(); - participantIdProperty.setName(String.valueOf(participantId.get(AC_ELEMENT_NAME))); - participantIdProperty.setVersion(String.valueOf(participantId.get(AC_ELEMENT_VERSION))); - automationCompositionElement.setParticipantId(participantIdProperty); - } - LinkedTreeMap<String, Object> participantType = - (LinkedTreeMap<String, Object>) template.getProperties().get(PARTICIPANT_TYPE_PROPERTY_KEY); - if (participantType != null) { - ToscaConceptIdentifier participantTypeProperty = new ToscaConceptIdentifier(); - participantTypeProperty.setName(String.valueOf(participantType.get(AC_ELEMENT_NAME))); - participantTypeProperty.setVersion(participantType.get(AC_ELEMENT_VERSION).toString()); - automationCompositionElement.setParticipantType(participantTypeProperty); - } - return automationCompositionElement; - } - - /** - * Deep clones ToscaNodeTemplate. - * - * @param serviceTemplate ToscaServiceTemplate - * @return a cloned Hash Map of ToscaNodeTemplate - */ - private Map<String, ToscaNodeTemplate> deepCloneNodeTemplate(ToscaServiceTemplate serviceTemplate) { - String jsonString = GSON.toJson(serviceTemplate.getToscaTopologyTemplate().getNodeTemplates()); - Type type = new TypeToken<HashMap<String, ToscaNodeTemplate>>() {}.getType(); - return GSON.fromJson(jsonString, type); - } - - /** - * Updates Automation composition instance name. - * - * @param oldInstanceName previous saved instance name - * @param newInstanceName new instance name to replace the previous one - * @return AutomationCompositions updated - * @throws PfModelException exception to compositions is not defined - */ - private AutomationCompositions updateAutomationComposition( - String oldInstanceName, String newInstanceName) throws PfModelException { - - List<AutomationComposition> filteredAcmList = automationCompositionProvider.getAutomationCompositions() - .stream().filter(acm -> acm.getName().contains(oldInstanceName)).collect(Collectors.toList()); - - if (filteredAcmList.isEmpty()) { - throw new PfModelException(Status.BAD_REQUEST, "Automation compositions not defined!"); - } - - AutomationComposition automationComposition = filteredAcmList.get(0); - - automationComposition.getDefinition() - .setName(updateInstanceNameDescription(newInstanceName, oldInstanceName, - automationComposition.getDefinition().getName())); - - automationComposition.setName(newInstanceName); - - automationComposition.setDescription( - updateInstanceNameDescription(newInstanceName, oldInstanceName, - automationComposition.getDescription())); - - automationComposition.getElements().forEach((uuid, automationCompositionElement) -> { - automationCompositionElement.getDefinition() - .setName(updateInstanceNameDescription(newInstanceName, oldInstanceName, - automationCompositionElement.getDefinition().getName())); - }); - - AutomationCompositions automationCompositions = new AutomationCompositions(); - automationCompositions.getAutomationCompositionList().add(automationComposition); - - return automationCompositions; - - } - - /** - * Updates instance and description. - * - * @param newInstanceName new instance name to replace the previous one - * @param oldInstanceName previous saved instance name - * @param value to be updated - * @return String updated instance name or description - */ - private String updateInstanceNameDescription( - String newInstanceName, String oldInstanceName, String value) { - String toBeReplaced = value.substring(value.indexOf(oldInstanceName)); - - String replace = value.replace(toBeReplaced, newInstanceName); - - return replace; - } } diff --git a/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/main/rest/CommissioningController.java b/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/main/rest/CommissioningController.java index 4cd384ede..fef1e6de9 100644 --- a/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/main/rest/CommissioningController.java +++ b/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/main/rest/CommissioningController.java @@ -29,9 +29,7 @@ import io.swagger.annotations.Extension; import io.swagger.annotations.ExtensionProperty; import io.swagger.annotations.ResponseHeader; import java.util.List; -import java.util.Map; import java.util.UUID; -import javax.ws.rs.core.Response.Status; import lombok.RequiredArgsConstructor; import org.onap.policy.clamp.acm.runtime.commissioning.CommissioningProvider; import org.onap.policy.clamp.acm.runtime.main.web.AbstractRestController; @@ -312,140 +310,4 @@ public class CommissioningController extends AbstractRestController { return ResponseEntity.ok().body(provider.getToscaServiceTemplateReduced(name, version, instanceName)); } - - /** - * Retrieves the Common or Instance Properties for the specified Tosca Service Template. - * - * @param requestId request ID used in ONAP logging - * @param common a flag, true to get common properties, false to get instance properties - * @param name the name of the tosca service template to retrieve - * @param version the version of the tosca service template to get - * @return the specified tosca service template or section Json Schema - * @throws PfModelException on errors getting the Common or Instance Properties - */ - // @formatter:off - @GetMapping(value = "/commission/getCommonOrInstanceProperties", - produces = {MediaType.APPLICATION_JSON_VALUE, APPLICATION_YAML}) - @ApiOperation(value = "Query details of the requested tosca service template common or instance properties", - notes = "Queries details of the requested commissioned tosca service template json common" - + "or instance properties, returning all tosca service template common or instance property details", - response = ToscaServiceTemplate.class, - tags = {"Clamp Automation Composition Commissioning API"}, - authorizations = @Authorization(value = AUTHORIZATION_TYPE), - responseHeaders = { - @ResponseHeader( - name = VERSION_MINOR_NAME, description = VERSION_MINOR_DESCRIPTION, - response = String.class), - @ResponseHeader(name = VERSION_PATCH_NAME, description = VERSION_PATCH_DESCRIPTION, - response = String.class), - @ResponseHeader(name = VERSION_LATEST_NAME, description = VERSION_LATEST_DESCRIPTION, - response = String.class), - @ResponseHeader(name = REQUEST_ID_NAME, description = REQUEST_ID_HDR_DESCRIPTION, - response = UUID.class)}, - extensions = { - @Extension - ( - name = EXTENSION_NAME, - properties = { - @ExtensionProperty(name = API_VERSION_NAME, value = API_VERSION), - @ExtensionProperty(name = LAST_MOD_NAME, value = LAST_MOD_RELEASE) - } - ) - } - ) - @ApiResponses( - value = { - @ApiResponse(code = AUTHENTICATION_ERROR_CODE, message = AUTHENTICATION_ERROR_MESSAGE), - @ApiResponse(code = AUTHORIZATION_ERROR_CODE, message = AUTHORIZATION_ERROR_MESSAGE), - @ApiResponse(code = SERVER_ERROR_CODE, message = SERVER_ERROR_MESSAGE) - } - ) - // @formatter:on - public ResponseEntity<Map<String, ToscaNodeTemplate>> queryToscaServiceCommonOrInstanceProperties( - @RequestHeader(name = REQUEST_ID_NAME, required = false) @ApiParam(REQUEST_ID_PARAM_DESCRIPTION) UUID requestId, - @ApiParam(value = "Tosca service template name", required = false) @RequestParam( - value = "name", - required = false) String name, - @ApiParam(value = "Tosca service template version", required = false) @RequestParam( - value = "version", - required = false) String version, - @ApiParam(value = "Automation composition name", required = false) @RequestParam( - value = "instanceName", - required = false) String instanceName, - @ApiParam( - value = "Flag, true for common properties, false for instance", - required = false) - @RequestParam(value = "common", defaultValue = "false", required = false) boolean common) - throws PfModelException { - - return ResponseEntity.ok().body(provider - .getNodeTemplatesWithCommonOrInstanceProperties(name, version, instanceName, common)); - } - - /** - * Queries the elements of a specific automation composition. - * - * @param requestId request ID used in ONAP logging - * @param name the name of the automation composition definition to get - * @param version the version of the automation composition definition to get - * @return the automation composition element definitions - * @throws PfModelException on errors getting the elements of a specific automation composition - */ - // @formatter:off - @GetMapping(value = "/commission/elements", - produces = {MediaType.APPLICATION_JSON_VALUE, APPLICATION_YAML}) - @ApiOperation(value = "Query details of the requested commissioned automation composition element definitions", - notes = "Queries details of the requested commissioned automation composition element definitions, " - + "returning all automation composition elements' details", - response = ToscaNodeTemplate.class, - tags = {TAGS}, - authorizations = @Authorization(value = AUTHORIZATION_TYPE), - responseHeaders = { - @ResponseHeader( - name = VERSION_MINOR_NAME, description = VERSION_MINOR_DESCRIPTION, - response = String.class), - @ResponseHeader(name = VERSION_PATCH_NAME, description = VERSION_PATCH_DESCRIPTION, - response = String.class), - @ResponseHeader(name = VERSION_LATEST_NAME, description = VERSION_LATEST_DESCRIPTION, - response = String.class), - @ResponseHeader(name = REQUEST_ID_NAME, description = REQUEST_ID_HDR_DESCRIPTION, - response = UUID.class)}, - extensions = { - @Extension - ( - name = EXTENSION_NAME, - properties = { - @ExtensionProperty(name = API_VERSION_NAME, value = API_VERSION), - @ExtensionProperty(name = LAST_MOD_NAME, value = LAST_MOD_RELEASE) - } - ) - } - ) - @ApiResponses( - value = { - @ApiResponse(code = AUTHENTICATION_ERROR_CODE, message = AUTHENTICATION_ERROR_MESSAGE), - @ApiResponse(code = AUTHORIZATION_ERROR_CODE, message = AUTHORIZATION_ERROR_MESSAGE), - @ApiResponse(code = SERVER_ERROR_CODE, message = SERVER_ERROR_MESSAGE) - } - ) - // @formatter:on - public ResponseEntity<List<ToscaNodeTemplate>> queryElements( - @RequestHeader(name = REQUEST_ID_NAME, required = false) @ApiParam(REQUEST_ID_PARAM_DESCRIPTION) UUID requestId, - @ApiParam(value = "Automation composition definition name", required = false) @RequestParam( - value = "name", - required = false) String name, - @ApiParam(value = "Automation composition definition version", required = false) @RequestParam( - value = "version", - required = false) String version) - throws PfModelException { - - List<ToscaNodeTemplate> nodeTemplate = provider.getAutomationCompositionDefinitions(name, version); - // Prevent ambiguous queries with multiple returns - if (nodeTemplate.size() > 1) { - throw new PfModelException(Status.NOT_ACCEPTABLE, "Multiple automation compositions are not supported"); - } - - List<ToscaNodeTemplate> response = provider.getAutomationCompositionElementDefinitions(nodeTemplate.get(0)); - return ResponseEntity.ok().body(response); - } } diff --git a/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/main/rest/InstantiationController.java b/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/main/rest/InstantiationController.java index b4d978d77..ba00c0ede 100644 --- a/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/main/rest/InstantiationController.java +++ b/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/main/rest/InstantiationController.java @@ -35,13 +35,9 @@ import org.onap.policy.clamp.acm.runtime.instantiation.AutomationCompositionInst import org.onap.policy.clamp.acm.runtime.main.web.AbstractRestController; import org.onap.policy.clamp.common.acm.exception.AutomationCompositionException; import org.onap.policy.clamp.models.acm.concepts.AutomationCompositions; -import org.onap.policy.clamp.models.acm.messages.rest.instantiation.AutomationCompositionOrderStateResponse; -import org.onap.policy.clamp.models.acm.messages.rest.instantiation.AutomationCompositionPrimedResponse; -import org.onap.policy.clamp.models.acm.messages.rest.instantiation.InstancePropertiesResponse; import org.onap.policy.clamp.models.acm.messages.rest.instantiation.InstantiationCommand; import org.onap.policy.clamp.models.acm.messages.rest.instantiation.InstantiationResponse; import org.onap.policy.models.base.PfModelException; -import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate; import org.springframework.http.MediaType; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.DeleteMapping; @@ -131,201 +127,6 @@ public class InstantiationController extends AbstractRestController { } /** - * Saves instance properties. - * - * @param requestId request ID used in ONAP logging - * @param body the body of automation composition following TOSCA definition - * @return a response - */ - // @formatter:off - @PostMapping(value = "/instanceProperties", - consumes = {MediaType.APPLICATION_JSON_VALUE, APPLICATION_YAML}, - produces = {MediaType.APPLICATION_JSON_VALUE, APPLICATION_YAML}) - @ApiOperation( - value = "Saves instance properties", - notes = "Saves instance properties, returning the saved instances properties and it's version", - response = InstancePropertiesResponse.class, - tags = {TAGS}, - authorizations = @Authorization(value = AUTHORIZATION_TYPE), - responseHeaders = { - @ResponseHeader( - name = VERSION_MINOR_NAME, - description = VERSION_MINOR_DESCRIPTION, - response = String.class), - @ResponseHeader( - name = VERSION_PATCH_NAME, - description = VERSION_PATCH_DESCRIPTION, - response = String.class), - @ResponseHeader( - name = VERSION_LATEST_NAME, - description = VERSION_LATEST_DESCRIPTION, - response = String.class), - @ResponseHeader( - name = REQUEST_ID_NAME, - description = REQUEST_ID_HDR_DESCRIPTION, - response = UUID.class) - }, - extensions = { - @Extension - ( - name = EXTENSION_NAME, - properties = { - @ExtensionProperty(name = API_VERSION_NAME, value = API_VERSION), - @ExtensionProperty(name = LAST_MOD_NAME, value = LAST_MOD_RELEASE) - } - ) - } - ) - @ApiResponses( - value = { - @ApiResponse(code = AUTHENTICATION_ERROR_CODE, message = AUTHENTICATION_ERROR_MESSAGE), - @ApiResponse(code = AUTHORIZATION_ERROR_CODE, message = AUTHORIZATION_ERROR_MESSAGE), - @ApiResponse(code = SERVER_ERROR_CODE, message = SERVER_ERROR_MESSAGE) - } - ) - // @formatter:on - public ResponseEntity<InstancePropertiesResponse> createInstanceProperties( - @RequestHeader(name = REQUEST_ID_NAME, required = false) @ApiParam(REQUEST_ID_PARAM_DESCRIPTION) UUID requestId, - @ApiParam(value = "Body of instance properties", required = true) @RequestBody ToscaServiceTemplate body) - throws PfModelException { - - return ResponseEntity.ok().body(provider.createInstanceProperties(body)); - } - - /** - * Updates instance properties. - * - * @param name the name of the automation composition to update - * @param version the version of the automation composition to update - * @param body the body of automation composition following TOSCA definition - * @return a response - */ - // @formatter:off - @PutMapping(value = "/instanceProperties", - consumes = {MediaType.APPLICATION_JSON_VALUE, APPLICATION_YAML}, - produces = {MediaType.APPLICATION_JSON_VALUE, APPLICATION_YAML}) - @ApiOperation( - value = "Updates instance properties", - notes = "Updates instance properties, returning the saved instances properties and it's version", - response = InstancePropertiesResponse.class, - tags = {TAGS}, - authorizations = @Authorization(value = AUTHORIZATION_TYPE), - responseHeaders = { - @ResponseHeader( - name = VERSION_MINOR_NAME, - description = VERSION_MINOR_DESCRIPTION, - response = String.class), - @ResponseHeader( - name = VERSION_PATCH_NAME, - description = VERSION_PATCH_DESCRIPTION, - response = String.class), - @ResponseHeader( - name = VERSION_LATEST_NAME, - description = VERSION_LATEST_DESCRIPTION, - response = String.class), - @ResponseHeader( - name = REQUEST_ID_NAME, - description = REQUEST_ID_HDR_DESCRIPTION, - response = UUID.class) - }, - extensions = { - @Extension - ( - name = EXTENSION_NAME, - properties = { - @ExtensionProperty(name = API_VERSION_NAME, value = API_VERSION), - @ExtensionProperty(name = LAST_MOD_NAME, value = LAST_MOD_RELEASE) - } - ) - } - ) - @ApiResponses( - value = { - @ApiResponse(code = AUTHENTICATION_ERROR_CODE, message = AUTHENTICATION_ERROR_MESSAGE), - @ApiResponse(code = AUTHORIZATION_ERROR_CODE, message = AUTHORIZATION_ERROR_MESSAGE), - @ApiResponse(code = SERVER_ERROR_CODE, message = SERVER_ERROR_MESSAGE) - } - ) - // @formatter:on - public ResponseEntity<InstancePropertiesResponse> updatesInstanceProperties( - @RequestHeader(name = REQUEST_ID_NAME, required = false) - @ApiParam(REQUEST_ID_PARAM_DESCRIPTION) UUID requestId, - @ApiParam(value = "Automation composition definition name", required = true) - @RequestParam("name") String name, - @ApiParam(value = "Automation composition definition version", required = true) - @RequestParam("version") String version, - @ApiParam(value = "Body of instance properties", required = true) @RequestBody ToscaServiceTemplate body) - throws PfModelException { - - return ResponseEntity.ok().body(provider.updatesInstanceProperties(name, version, body)); - } - - /** - * Deletes a automation composition definition and instance properties. - * - * @param requestId request ID used in ONAP logging - * @param name the name of the automation composition to delete - * @param version the version of the automation composition to delete - * @return a response - * @throws PfModelException on errors deleting of automation composition and instance properties - */ - // @formatter:off - @DeleteMapping(value = "/instanceProperties", - produces = {MediaType.APPLICATION_JSON_VALUE, APPLICATION_YAML}) - @ApiOperation(value = "Delete a automation composition and instance properties", - notes = "Deletes a automation composition and instance properties, returning optional error details", - response = InstantiationResponse.class, - tags = {TAGS}, - authorizations = @Authorization(value = AUTHORIZATION_TYPE), - responseHeaders = { - @ResponseHeader( - name = VERSION_MINOR_NAME, - description = VERSION_MINOR_DESCRIPTION, - response = String.class), - @ResponseHeader( - name = VERSION_PATCH_NAME, - description = VERSION_PATCH_DESCRIPTION, - response = String.class), - @ResponseHeader( - name = VERSION_LATEST_NAME, - description = VERSION_LATEST_DESCRIPTION, - response = String.class), - @ResponseHeader( - name = REQUEST_ID_NAME, - description = REQUEST_ID_HDR_DESCRIPTION, - response = UUID.class)}, - extensions = { - @Extension - ( - name = EXTENSION_NAME, - properties = { - @ExtensionProperty(name = API_VERSION_NAME, value = API_VERSION), - @ExtensionProperty(name = LAST_MOD_NAME, value = LAST_MOD_RELEASE) - } - ) - } - ) - @ApiResponses( - value = { - @ApiResponse(code = AUTHENTICATION_ERROR_CODE, message = AUTHENTICATION_ERROR_MESSAGE), - @ApiResponse(code = AUTHORIZATION_ERROR_CODE, message = AUTHORIZATION_ERROR_MESSAGE), - @ApiResponse(code = SERVER_ERROR_CODE, message = SERVER_ERROR_MESSAGE) - } - ) - // @formatter:on - - public ResponseEntity<InstantiationResponse> deleteInstanceProperties( - @RequestHeader(name = REQUEST_ID_NAME, required = false) @ApiParam(REQUEST_ID_PARAM_DESCRIPTION) UUID requestId, - @ApiParam(value = "Automation composition definition name", required = true) @RequestParam("name") String name, - @ApiParam(value = "Automation composition definition version") @RequestParam( - value = "version", - required = true) String version) - throws PfModelException { - - return ResponseEntity.ok().body(provider.deleteInstanceProperties(name, version)); - } - - /** * Queries details of all automation compositions. * * @param requestId request ID used in ONAP logging @@ -570,122 +371,4 @@ public class InstantiationController extends AbstractRestController { return ResponseEntity.accepted().body(provider.issueAutomationCompositionCommand(command)); } - - /** - * Queries details of all automation compositions. - * - * @param requestId request ID used in ONAP logging - * @param name the name of the automation composition to get, null for all automation compositions - * @param version the version of the automation composition to get, null for all automation compositions - * @return the automation compositions - * @throws PfModelException on errors getting commissioning of automation composition - */ - // @formatter:off - @GetMapping(value = "/instantiationState", - produces = {MediaType.APPLICATION_JSON_VALUE, APPLICATION_YAML}) - @ApiOperation(value = "Query details of the requested automation compositions", - notes = "Queries details of requested automation compositions, returning all automation composition details", - response = AutomationCompositions.class, - tags = {TAGS}, - authorizations = @Authorization(value = AUTHORIZATION_TYPE), - responseHeaders = { - @ResponseHeader( - name = VERSION_MINOR_NAME, description = VERSION_MINOR_DESCRIPTION, - response = String.class), - @ResponseHeader(name = VERSION_PATCH_NAME, description = VERSION_PATCH_DESCRIPTION, - response = String.class), - @ResponseHeader(name = VERSION_LATEST_NAME, description = VERSION_LATEST_DESCRIPTION, - response = String.class), - @ResponseHeader(name = REQUEST_ID_NAME, description = REQUEST_ID_HDR_DESCRIPTION, - response = UUID.class)}, - extensions = { - @Extension - ( - name = EXTENSION_NAME, - properties = { - @ExtensionProperty(name = API_VERSION_NAME, value = API_VERSION), - @ExtensionProperty(name = LAST_MOD_NAME, value = LAST_MOD_RELEASE) - } - ) - } - ) - @ApiResponses( - value = { - @ApiResponse(code = AUTHENTICATION_ERROR_CODE, message = AUTHENTICATION_ERROR_MESSAGE), - @ApiResponse(code = AUTHORIZATION_ERROR_CODE, message = AUTHORIZATION_ERROR_MESSAGE), - @ApiResponse(code = SERVER_ERROR_CODE, message = SERVER_ERROR_MESSAGE) - } - ) - // @formatter:on - public ResponseEntity<AutomationCompositionOrderStateResponse> getInstantiationOrderState( - @RequestHeader(name = REQUEST_ID_NAME, required = false) @ApiParam(REQUEST_ID_PARAM_DESCRIPTION) UUID requestId, - @ApiParam(value = "Automation composition name", required = false) @RequestParam( - value = "name", - required = false) String name, - @ApiParam(value = "Automation composition version", required = false) @RequestParam( - value = "version", - required = false) String version) - throws PfModelException { - - return ResponseEntity.ok().body(provider.getInstantiationOrderState(name, version)); - } - - /** - * Queries Primed/De-Primed status of a automation composition. - * - * @param requestId request ID used in ONAP logging - * @param name the name of the automation composition to get, null for all automation compositions - * @param version the version of the automation composition to get, null for all automation compositions - * @return the automation compositions - * @throws PfModelException on errors getting priming of automation composition - */ - // @formatter:off - @GetMapping(value = "/automationCompositionPriming", - produces = {MediaType.APPLICATION_JSON_VALUE, APPLICATION_YAML}) - @ApiOperation(value = "Query priming details of the requested automation compositions", - notes = "Queries priming details of requested automation compositions, returning primed/deprimed compositions", - response = AutomationCompositionPrimedResponse.class, - tags = {TAGS}, - authorizations = @Authorization(value = AUTHORIZATION_TYPE), - responseHeaders = { - @ResponseHeader( - name = VERSION_MINOR_NAME, description = VERSION_MINOR_DESCRIPTION, - response = String.class), - @ResponseHeader(name = VERSION_PATCH_NAME, description = VERSION_PATCH_DESCRIPTION, - response = String.class), - @ResponseHeader(name = VERSION_LATEST_NAME, description = VERSION_LATEST_DESCRIPTION, - response = String.class), - @ResponseHeader(name = REQUEST_ID_NAME, description = REQUEST_ID_HDR_DESCRIPTION, - response = UUID.class)}, - extensions = { - @Extension - ( - name = EXTENSION_NAME, - properties = { - @ExtensionProperty(name = API_VERSION_NAME, value = API_VERSION), - @ExtensionProperty(name = LAST_MOD_NAME, value = LAST_MOD_RELEASE) - } - ) - } - ) - @ApiResponses( - value = { - @ApiResponse(code = AUTHENTICATION_ERROR_CODE, message = AUTHENTICATION_ERROR_MESSAGE), - @ApiResponse(code = AUTHORIZATION_ERROR_CODE, message = AUTHORIZATION_ERROR_MESSAGE), - @ApiResponse(code = SERVER_ERROR_CODE, message = SERVER_ERROR_MESSAGE) - } - ) - // @formatter:on - public ResponseEntity<AutomationCompositionPrimedResponse> getAutomationCompositionPriming( - @RequestHeader(name = REQUEST_ID_NAME, required = false) @ApiParam(REQUEST_ID_PARAM_DESCRIPTION) UUID requestId, - @ApiParam(value = "Automation composition definition name", required = false) @RequestParam( - value = "name", - required = false) String name, - @ApiParam(value = "Automation composition definition version", required = false) @RequestParam( - value = "version", - required = false) String version) - throws PfModelException { - - return ResponseEntity.ok().body(provider.getAutomationCompositionPriming(name, version)); - } } diff --git a/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/commissioning/rest/CommissioningControllerTest.java b/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/commissioning/rest/CommissioningControllerTest.java index 0cc2036e7..f34e5eff0 100644 --- a/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/commissioning/rest/CommissioningControllerTest.java +++ b/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/commissioning/rest/CommissioningControllerTest.java @@ -30,7 +30,6 @@ import static org.onap.policy.clamp.acm.runtime.util.CommonTestData.TOSCA_SERVIC import static org.onap.policy.clamp.acm.runtime.util.CommonTestData.TOSCA_ST_TEMPLATE_YAML; import java.util.List; -import java.util.Map; import javax.ws.rs.client.Entity; import javax.ws.rs.client.Invocation; import javax.ws.rs.core.Response; @@ -45,7 +44,6 @@ import org.onap.policy.clamp.acm.runtime.instantiation.InstantiationUtils; import org.onap.policy.clamp.acm.runtime.util.rest.CommonRestController; import org.onap.policy.clamp.models.acm.messages.rest.commissioning.CommissioningResponse; import org.onap.policy.clamp.models.acm.persistence.provider.ServiceTemplateProvider; -import org.onap.policy.models.tosca.authorative.concepts.ToscaNodeTemplate; import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; @@ -142,22 +140,6 @@ class CommissioningControllerTest extends CommonRestController { } @Test - void testQueryCommonOrInstanceProperties() throws Exception { - createFullEntryInDbWithCommonProps(); - - Invocation.Builder invocationBuilder = super.sendRequest(COMMISSIONING_ENDPOINT - + "/getCommonOrInstanceProperties?common=true"); - Response rawresp = invocationBuilder.buildGet().invoke(); - assertEquals(Response.Status.OK.getStatusCode(), rawresp.getStatus()); - - @SuppressWarnings("unchecked") - Map<String, ToscaNodeTemplate> commonProperties = rawresp.readEntity(Map.class); - - assertNotNull(commonProperties); - assertThat(commonProperties).hasSize(4); - } - - @Test void testCreateBadRequest() { Invocation.Builder invocationBuilder = super.sendRequest(COMMISSIONING_ENDPOINT); Response resp = invocationBuilder.post(Entity.json("NotToscaServiceTempalte")); @@ -209,29 +191,6 @@ class CommissioningControllerTest extends CommonRestController { } @Test - void testQueryElementsBadRequest() throws Exception { - createEntryInDB(); - - // Call get elements with no info - Invocation.Builder invocationBuilder = super.sendRequest(COMMISSIONING_ENDPOINT + "/elements"); - Response resp = invocationBuilder.buildGet().invoke(); - assertEquals(Response.Status.NOT_ACCEPTABLE.getStatusCode(), resp.getStatus()); - } - - @Test - void testQueryElements() throws Exception { - createEntryInDB(); - - Invocation.Builder invocationBuilder = super.sendRequest(COMMISSIONING_ENDPOINT + "/elements" - + "?name=org.onap.domain.pmsh.PMSHAutomationCompositionDefinition"); - Response rawresp = invocationBuilder.buildGet().invoke(); - assertEquals(Response.Status.OK.getStatusCode(), rawresp.getStatus()); - List<?> entityList = rawresp.readEntity(List.class); - assertNotNull(entityList); - assertThat(entityList).hasSize(4); - } - - @Test void testDeleteBadRequest() throws Exception { createEntryInDB(); diff --git a/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/instantiation/AutomationCompositionInstantiationProviderTest.java b/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/instantiation/AutomationCompositionInstantiationProviderTest.java index b826eebbc..016ec6c5e 100644 --- a/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/instantiation/AutomationCompositionInstantiationProviderTest.java +++ b/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/instantiation/AutomationCompositionInstantiationProviderTest.java @@ -23,17 +23,13 @@ package org.onap.policy.clamp.acm.runtime.instantiation; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatThrownBy; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertNull; import static org.mockito.ArgumentMatchers.anyString; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; -import static org.onap.policy.clamp.acm.runtime.util.CommonTestData.TOSCA_SERVICE_TEMPLATE_YAML; import java.util.List; import java.util.Optional; -import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; import org.mockito.Mockito; import org.onap.policy.clamp.acm.runtime.commissioning.CommissioningProvider; @@ -41,24 +37,19 @@ import org.onap.policy.clamp.acm.runtime.supervision.SupervisionHandler; import org.onap.policy.clamp.acm.runtime.util.CommonTestData; import org.onap.policy.clamp.common.acm.exception.AutomationCompositionRuntimeException; import org.onap.policy.clamp.models.acm.concepts.AutomationComposition; -import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionOrderedState; import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionState; import org.onap.policy.clamp.models.acm.concepts.AutomationCompositions; import org.onap.policy.clamp.models.acm.messages.rest.instantiation.InstantiationCommand; import org.onap.policy.clamp.models.acm.messages.rest.instantiation.InstantiationResponse; import org.onap.policy.clamp.models.acm.persistence.provider.AutomationCompositionProvider; import org.onap.policy.clamp.models.acm.persistence.provider.ParticipantProvider; -import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier; import org.onap.policy.models.tosca.authorative.concepts.ToscaNodeTemplate; -import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate; /** * Class to perform unit test of {@link AutomationCompositionInstantiationProvider}}. * */ class AutomationCompositionInstantiationProviderTest { - private static final String ID_NAME = "PMSH_Test_Instance"; - private static final String ID_VERSION = "1.2.3"; private static final String AC_INSTANTIATION_CREATE_JSON = "src/test/resources/rest/acm/AutomationCompositions.json"; private static final String AC_INSTANTIATION_UPDATE_JSON = @@ -89,54 +80,6 @@ class AutomationCompositionInstantiationProviderTest { + " {4}item \"AutomationComposition\" value \"org.onap.domain.PMSHAutomationCompositionDefinition\"" + " INVALID, Commissioned automation composition definition not found\n"; - private static ToscaServiceTemplate serviceTemplate = new ToscaServiceTemplate(); - - @BeforeAll - public static void setUpBeforeClass() { - serviceTemplate = InstantiationUtils.getToscaServiceTemplate(TOSCA_SERVICE_TEMPLATE_YAML); - } - - @Test - void testInstanceResponse() throws Exception { - var participantProvider = Mockito.mock(ParticipantProvider.class); - var acProvider = mock(AutomationCompositionProvider.class); - var supervisionHandler = mock(SupervisionHandler.class); - var commissioningProvider = mock(CommissioningProvider.class); - - when(commissioningProvider.getAllToscaServiceTemplate()).thenReturn(List.of(serviceTemplate)); - when(commissioningProvider.getToscaServiceTemplate(ID_NAME, ID_VERSION)).thenReturn(serviceTemplate); - - var instantiationProvider = new AutomationCompositionInstantiationProvider(acProvider, commissioningProvider, - supervisionHandler, participantProvider); - var instancePropertyList = instantiationProvider.createInstanceProperties(serviceTemplate); - assertNull(instancePropertyList.getErrorDetails()); - var id = new ToscaConceptIdentifier(ID_NAME, ID_VERSION); - assertEquals(id, instancePropertyList.getAffectedInstanceProperties().get(0)); - - AutomationCompositions automationCompositions = - InstantiationUtils.getAutomationCompositionsFromResource(AC_INSTANTIATION_CREATE_JSON, "Crud"); - var automationComposition = automationCompositions.getAutomationCompositionList().get(0); - automationComposition.setName(ID_NAME); - automationComposition.setVersion(ID_VERSION); - when(acProvider.getAutomationCompositions(ID_NAME, ID_VERSION)).thenReturn(List.of(automationComposition)); - - var updatedInstancePropertyList = instantiationProvider.createInstanceProperties(serviceTemplate); - assertNull(updatedInstancePropertyList.getErrorDetails()); - var updatedId = new ToscaConceptIdentifier(ID_NAME, ID_VERSION); - assertEquals(updatedId, instancePropertyList.getAffectedInstanceProperties().get(0)); - - var instanceOrderState = instantiationProvider.getInstantiationOrderState(ID_NAME, ID_VERSION); - assertEquals(AutomationCompositionOrderedState.UNINITIALISED, instanceOrderState.getOrderedState()); - assertEquals(ID_NAME, instanceOrderState.getAutomationCompositionIdentifierList().get(0).getName()); - - when(acProvider.findAutomationComposition(ID_NAME, ID_VERSION)).thenReturn(Optional.of(automationComposition)); - when(acProvider.deleteAutomationComposition(ID_NAME, ID_VERSION)).thenReturn(automationComposition); - - var instanceResponse = instantiationProvider.deleteInstanceProperties(ID_NAME, ID_VERSION); - assertEquals(ID_NAME, instanceResponse.getAffectedAutomationCompositions().get(0).getName()); - - } - @Test void testInstantiationCrud() throws Exception { var participantProvider = Mockito.mock(ParticipantProvider.class); diff --git a/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/instantiation/rest/InstantiationControllerTest.java b/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/instantiation/rest/InstantiationControllerTest.java index 35a3094cd..7cdc8a975 100644 --- a/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/instantiation/rest/InstantiationControllerTest.java +++ b/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/instantiation/rest/InstantiationControllerTest.java @@ -23,7 +23,6 @@ package org.onap.policy.clamp.acm.runtime.instantiation.rest; import static org.assertj.core.api.Assertions.assertThat; import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.junit.jupiter.api.Assertions.assertNull; import static org.onap.policy.clamp.acm.runtime.util.CommonTestData.TOSCA_SERVICE_TEMPLATE_YAML; @@ -42,11 +41,7 @@ import org.onap.policy.clamp.acm.runtime.main.rest.InstantiationController; import org.onap.policy.clamp.acm.runtime.util.CommonTestData; import org.onap.policy.clamp.acm.runtime.util.rest.CommonRestController; import org.onap.policy.clamp.models.acm.concepts.AutomationComposition; -import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionOrderedState; import org.onap.policy.clamp.models.acm.concepts.AutomationCompositions; -import org.onap.policy.clamp.models.acm.messages.rest.instantiation.AutomationCompositionOrderStateResponse; -import org.onap.policy.clamp.models.acm.messages.rest.instantiation.AutomationCompositionPrimedResponse; -import org.onap.policy.clamp.models.acm.messages.rest.instantiation.InstancePropertiesResponse; import org.onap.policy.clamp.models.acm.messages.rest.instantiation.InstantiationCommand; import org.onap.policy.clamp.models.acm.messages.rest.instantiation.InstantiationResponse; import org.onap.policy.clamp.models.acm.persistence.provider.ParticipantProvider; @@ -83,9 +78,6 @@ class InstantiationControllerTest extends CommonRestController { private static final String INSTANTIATION_ENDPOINT = "instantiation"; private static final String INSTANTIATION_COMMAND_ENDPOINT = "instantiation/command"; - private static final String PRIMING_ENDPOINT = "automationCompositionPriming"; - private static final String INSTANTIATION_PROPERTIES = "instanceProperties"; - private static final String INSTANTIATION_STATE = "instantiationState"; private static ToscaServiceTemplate serviceTemplate = new ToscaServiceTemplate(); @@ -185,14 +177,6 @@ class InstantiationControllerTest extends CommonRestController { assertEquals(automationCompositionFromRsc, automationCompositionsFromDb.getAutomationCompositionList().get(0)); } - - invocationBuilder = - super.sendRequest(PRIMING_ENDPOINT + "?name=" + "PMSHInstance0Create" + "&version=" + "1.0.1"); - Response rawresp = invocationBuilder.buildGet().invoke(); - assertEquals(Response.Status.OK.getStatusCode(), rawresp.getStatus()); - AutomationCompositionPrimedResponse primResponse = - rawresp.readEntity(AutomationCompositionPrimedResponse.class); - assertFalse(primResponse.getPrimedAutomationCompositionsList().get(0).isPrimed()); } @Test @@ -273,17 +257,6 @@ class InstantiationControllerTest extends CommonRestController { } @Test - void testDelete_NoResultWithThisName() { - Invocation.Builder invocationBuilder = - super.sendRequest(INSTANTIATION_ENDPOINT + "?name=noResultWithThisName&version=1.0.1"); - Response resp = invocationBuilder.delete(); - assertEquals(Response.Status.NOT_FOUND.getStatusCode(), resp.getStatus()); - InstantiationResponse instResponse = resp.readEntity(InstantiationResponse.class); - assertNotNull(instResponse.getErrorDetails()); - assertNull(instResponse.getAffectedAutomationCompositions()); - } - - @Test void testDelete() throws Exception { AutomationCompositions automationCompositionsFromRsc = @@ -325,89 +298,6 @@ class InstantiationControllerTest extends CommonRestController { } @Test - void testCreateInstanceProperties() { - Invocation.Builder invocationBuilder = super.sendRequest(INSTANTIATION_PROPERTIES); - Response resp = invocationBuilder.post(Entity.json(serviceTemplate)); - assertEquals(Response.Status.OK.getStatusCode(), resp.getStatus()); - var instancePropertyList = resp.readEntity(InstancePropertiesResponse.class); - assertNull(instancePropertyList.getErrorDetails()); - var id = new ToscaConceptIdentifier(ID_NAME, ID_VERSION); - assertEquals(id, instancePropertyList.getAffectedInstanceProperties().get(0)); - - invocationBuilder = super.sendRequest(INSTANTIATION_ENDPOINT); - resp = invocationBuilder.get(); - assertEquals(Response.Status.OK.getStatusCode(), resp.getStatus()); - var automationCompositionsGet = resp.readEntity(AutomationCompositions.class); - assertThat(automationCompositionsGet.getAutomationCompositionList()).hasSize(1); - } - - @Test - void testDeleteInstanceProperties() throws Exception { - Invocation.Builder invocationBuilder = super.sendRequest(INSTANTIATION_PROPERTIES); - Response resp = invocationBuilder.post(Entity.json(serviceTemplate)); - assertEquals(Response.Status.OK.getStatusCode(), resp.getStatus()); - - invocationBuilder = super.sendRequest(INSTANTIATION_PROPERTIES + "?name=" + ID_NAME + "&version=" + ID_VERSION); - resp = invocationBuilder.delete(); - assertEquals(Response.Status.OK.getStatusCode(), resp.getStatus()); - var instanceResponse = resp.readEntity(InstantiationResponse.class); - assertEquals(ID_NAME, instanceResponse.getAffectedAutomationCompositions().get(0).getName()); - AutomationCompositions automationCompositionsGet = - instantiationProvider.getAutomationCompositions(ID_NAME, ID_VERSION); - assertThat(automationCompositionsGet.getAutomationCompositionList()).isEmpty(); - } - - @Test - void testDeleteInstancePropertiesBadRequest() { - Invocation.Builder invocationBuilder = super.sendRequest(INSTANTIATION_PROPERTIES); - Response resp = invocationBuilder.post(Entity.json(serviceTemplate)); - assertEquals(Response.Status.OK.getStatusCode(), resp.getStatus()); - - invocationBuilder = super.sendRequest(INSTANTIATION_PROPERTIES + "?name=" + ID_NAME); - resp = invocationBuilder.delete(); - assertEquals(Response.Status.BAD_REQUEST.getStatusCode(), resp.getStatus()); - } - - @Test - void testDeleteInstancePropertiesPassiveMode() throws Exception { - Invocation.Builder invocationBuilder = super.sendRequest(INSTANTIATION_PROPERTIES); - Response resp = invocationBuilder.post(Entity.json(serviceTemplate)); - assertEquals(Response.Status.OK.getStatusCode(), resp.getStatus()); - - var automationCompositions = - InstantiationUtils.getAutomationCompositionsFromResource(AC_INSTANTIATION_CREATE_JSON, "Command"); - instantiationProvider.createAutomationCompositions(automationCompositions); - - var participants = CommonTestData.createParticipants(); - for (var participant : participants) { - participantProvider.saveParticipant(participant); - } - - InstantiationCommand command = - InstantiationUtils.getInstantiationCommandFromResource(AC_INSTANTIATION_CHANGE_STATE_JSON, "Command"); - - invocationBuilder = super.sendRequest(INSTANTIATION_COMMAND_ENDPOINT); - resp = invocationBuilder.put(Entity.json(command)); - assertEquals(Response.Status.ACCEPTED.getStatusCode(), resp.getStatus()); - InstantiationResponse instResponse = resp.readEntity(InstantiationResponse.class); - InstantiationUtils.assertInstantiationResponse(instResponse, command); - - // check passive state on DB and delete properties - for (ToscaConceptIdentifier toscaConceptIdentifier : command.getAutomationCompositionIdentifierList()) { - AutomationCompositions automationCompositionsGet = instantiationProvider - .getAutomationCompositions(toscaConceptIdentifier.getName(), toscaConceptIdentifier.getVersion()); - assertThat(automationCompositionsGet.getAutomationCompositionList()).hasSize(1); - assertEquals(command.getOrderedState(), - automationCompositionsGet.getAutomationCompositionList().get(0).getOrderedState()); - - invocationBuilder = super.sendRequest(INSTANTIATION_PROPERTIES + "?name=" + toscaConceptIdentifier.getName() - + "&version=" + toscaConceptIdentifier.getVersion()); - resp = invocationBuilder.delete(); - assertEquals(Response.Status.BAD_REQUEST.getStatusCode(), resp.getStatus()); - } - } - - @Test void testCommand_NotFound1() { Invocation.Builder invocationBuilder = super.sendRequest(INSTANTIATION_COMMAND_ENDPOINT); Response resp = invocationBuilder.put(Entity.json(new InstantiationCommand())); @@ -455,78 +345,6 @@ class InstantiationControllerTest extends CommonRestController { } } - @Test - void testIntanceProperties() throws Exception { - Invocation.Builder invocationBuilder = super.sendRequest(INSTANTIATION_PROPERTIES); - Response resp = invocationBuilder.post(Entity.json(serviceTemplate)); - assertEquals(Response.Status.OK.getStatusCode(), resp.getStatus()); - var instancePropertyList = resp.readEntity(InstancePropertiesResponse.class); - assertNull(instancePropertyList.getErrorDetails()); - var id = new ToscaConceptIdentifier(ID_NAME, ID_VERSION); - assertEquals(id, instancePropertyList.getAffectedInstanceProperties().get(0)); - - invocationBuilder = super.sendRequest(INSTANTIATION_STATE + "?name=" + ID_NAME + "&version=" + ID_VERSION); - resp = invocationBuilder.buildGet().invoke(); - assertEquals(Response.Status.OK.getStatusCode(), resp.getStatus()); - var instanceOrderState = resp.readEntity(AutomationCompositionOrderStateResponse.class); - assertEquals(AutomationCompositionOrderedState.UNINITIALISED, instanceOrderState.getOrderedState()); - assertEquals(ID_NAME, instanceOrderState.getAutomationCompositionIdentifierList().get(0).getName()); - AutomationCompositions automationCompositionsGet = - instantiationProvider.getAutomationCompositions(ID_NAME, ID_VERSION); - assertThat(automationCompositionsGet.getAutomationCompositionList()).hasSize(1); - - invocationBuilder = super.sendRequest(INSTANTIATION_PROPERTIES + "?name=" + ID_NAME + "&version=" + ID_VERSION); - resp = invocationBuilder.delete(); - assertEquals(Response.Status.OK.getStatusCode(), resp.getStatus()); - var instanceResponse = resp.readEntity(InstantiationResponse.class); - assertEquals(ID_NAME, instanceResponse.getAffectedAutomationCompositions().get(0).getName()); - automationCompositionsGet = instantiationProvider.getAutomationCompositions(ID_NAME, ID_VERSION); - assertThat(automationCompositionsGet.getAutomationCompositionList()).isEmpty(); - } - - @Test - void testChangeOrderStateFromUninitializedPassiveMode() throws Exception { - Invocation.Builder invocationBuilder = super.sendRequest(INSTANTIATION_PROPERTIES); - Response resp = invocationBuilder.post(Entity.json(serviceTemplate)); - assertEquals(Response.Status.OK.getStatusCode(), resp.getStatus()); - - var automationCompositions = - InstantiationUtils.getAutomationCompositionsFromResource(AC_INSTANTIATION_CREATE_JSON, "CommandPassive"); - instantiationProvider.createAutomationCompositions(automationCompositions); - - var participants = CommonTestData.createParticipants(); - for (var participant : participants) { - participantProvider.saveParticipant(participant); - } - - InstantiationCommand command = InstantiationUtils - .getInstantiationCommandFromResource(AC_INSTANTIATION_CHANGE_STATE_JSON, "CommandPassive"); - - invocationBuilder = super.sendRequest(INSTANTIATION_COMMAND_ENDPOINT); - resp = invocationBuilder.put(Entity.json(command)); - assertEquals(Response.Status.ACCEPTED.getStatusCode(), resp.getStatus()); - InstantiationResponse instResponse = resp.readEntity(InstantiationResponse.class); - InstantiationUtils.assertInstantiationResponse(instResponse, command); - } - - @Test - void testChangeOrderStateWithoutRegisteredParticipants() throws Exception { - Invocation.Builder invocationBuilder = super.sendRequest(INSTANTIATION_PROPERTIES); - Response resp = invocationBuilder.post(Entity.json(serviceTemplate)); - assertEquals(Response.Status.OK.getStatusCode(), resp.getStatus()); - - var automationCompositions = - InstantiationUtils.getAutomationCompositionsFromResource(AC_INSTANTIATION_CREATE_JSON, "CommandPassive"); - instantiationProvider.createAutomationCompositions(automationCompositions); - - InstantiationCommand command = InstantiationUtils - .getInstantiationCommandFromResource(AC_INSTANTIATION_CHANGE_STATE_JSON, "CommandPassive"); - - invocationBuilder = super.sendRequest(INSTANTIATION_COMMAND_ENDPOINT); - resp = invocationBuilder.put(Entity.json(command)); - assertEquals(Response.Status.BAD_REQUEST.getStatusCode(), resp.getStatus()); - } - private synchronized void deleteEntryInDB() throws Exception { automationCompositionRepository.deleteAll(); var list = serviceTemplateProvider.getAllServiceTemplates(); |