diff options
Diffstat (limited to 'bpmn/so-bpmn-tasks/src/main')
10 files changed, 744 insertions, 60 deletions
diff --git a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/namingservice/tasks/NamingServiceCreateTasks.java b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/namingservice/tasks/NamingServiceCreateTasks.java new file mode 100644 index 0000000000..cb4ac5c9d9 --- /dev/null +++ b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/namingservice/tasks/NamingServiceCreateTasks.java @@ -0,0 +1,56 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.onap.so.bpmn.infrastructure.namingservice.tasks; + + +import org.onap.so.bpmn.common.BuildingBlockExecution; +import org.onap.so.bpmn.servicedecomposition.bbobjects.InstanceGroup; +import org.onap.so.bpmn.servicedecomposition.entities.ResourceKey; +import org.onap.so.bpmn.servicedecomposition.tasks.ExtractPojosForBB; +import org.onap.so.client.exception.ExceptionBuilder; +import org.onap.so.client.orchestration.NamingServiceResources; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; + +@Component +public class NamingServiceCreateTasks { + + @Autowired + private ExceptionBuilder exceptionUtil; + @Autowired + private ExtractPojosForBB extractPojosForBB; + + @Autowired + private NamingServiceResources namingServiceResources; + + public void createInstanceGroupName(BuildingBlockExecution execution) throws Exception { + InstanceGroup instanceGroup = extractPojosForBB.extractByKey(execution, ResourceKey.INSTANCE_GROUP_ID, execution.getLookupMap().get(ResourceKey.INSTANCE_GROUP_ID)); + String policyInstanceName = execution.getVariable("policyInstanceName"); + String nfNamingCode = execution.getVariable("nfNamingCode"); + String generatedInstanceGroupName = ""; + try { + generatedInstanceGroupName = namingServiceResources.generateInstanceGroupName(instanceGroup, policyInstanceName, nfNamingCode); + } catch (Exception ex) { + exceptionUtil.buildAndThrowWorkflowException(execution, 7000, ex); + } + instanceGroup.setInstanceGroupName(generatedInstanceGroupName); + } +} diff --git a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/namingservice/tasks/NamingServiceDeleteTasks.java b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/namingservice/tasks/NamingServiceDeleteTasks.java new file mode 100644 index 0000000000..ddea2724bc --- /dev/null +++ b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/namingservice/tasks/NamingServiceDeleteTasks.java @@ -0,0 +1,53 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.onap.so.bpmn.infrastructure.namingservice.tasks; + + +import org.onap.so.bpmn.common.BuildingBlockExecution; +import org.onap.so.bpmn.servicedecomposition.bbobjects.InstanceGroup; +import org.onap.so.bpmn.servicedecomposition.entities.ResourceKey; +import org.onap.so.bpmn.servicedecomposition.tasks.ExtractPojosForBB; +import org.onap.so.client.exception.ExceptionBuilder; +import org.onap.so.client.orchestration.NamingServiceResources; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; + +@Component +public class NamingServiceDeleteTasks { + + @Autowired + private ExceptionBuilder exceptionUtil; + @Autowired + private ExtractPojosForBB extractPojosForBB; + + @Autowired + private NamingServiceResources namingServiceResources; + + public void deleteInstanceGroupName(BuildingBlockExecution execution) throws Exception { + InstanceGroup instanceGroup = extractPojosForBB.extractByKey(execution, ResourceKey.INSTANCE_GROUP_ID, execution.getLookupMap().get(ResourceKey.INSTANCE_GROUP_ID)); + + try { + namingServiceResources.deleteInstanceGroupName(instanceGroup); + } catch (Exception ex) { + exceptionUtil.buildAndThrowWorkflowException(execution, 7000, ex); + } + } +} diff --git a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/sdnc/tasks/SDNCUnassignTasks.java b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/sdnc/tasks/SDNCUnassignTasks.java index 13639daa44..ab4a7f8a2c 100644 --- a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/sdnc/tasks/SDNCUnassignTasks.java +++ b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/sdnc/tasks/SDNCUnassignTasks.java @@ -24,6 +24,7 @@ import org.onap.so.bpmn.common.BuildingBlockExecution; import org.onap.so.bpmn.servicedecomposition.bbobjects.CloudRegion; import org.onap.so.bpmn.servicedecomposition.bbobjects.Customer; import org.onap.so.bpmn.servicedecomposition.bbobjects.GenericVnf; +import org.onap.so.bpmn.servicedecomposition.bbobjects.L3Network; import org.onap.so.bpmn.servicedecomposition.bbobjects.ServiceInstance; import org.onap.so.bpmn.servicedecomposition.bbobjects.VfModule; import org.onap.so.bpmn.servicedecomposition.entities.GeneralBuildingBlock; @@ -31,17 +32,14 @@ import org.onap.so.bpmn.servicedecomposition.entities.ResourceKey; import org.onap.so.bpmn.servicedecomposition.generalobjects.RequestContext; import org.onap.so.bpmn.servicedecomposition.tasks.ExtractPojosForBB; import org.onap.so.client.exception.ExceptionBuilder; +import org.onap.so.client.orchestration.SDNCNetworkResources; import org.onap.so.client.orchestration.SDNCServiceInstanceResources; import org.onap.so.client.orchestration.SDNCVfModuleResources; import org.onap.so.client.orchestration.SDNCVnfResources; -import org.onap.so.db.catalog.beans.OrchestrationStatus; import org.onap.so.logger.MsoLogger; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; -import org.onap.so.bpmn.servicedecomposition.bbobjects.L3Network; -import org.onap.so.client.orchestration.SDNCNetworkResources; - @Component public class SDNCUnassignTasks { private static final MsoLogger msoLogger = MsoLogger.getMsoLogger(MsoLogger.Catalog.BPEL, SDNCUnassignTasks.class); @@ -61,12 +59,7 @@ public class SDNCUnassignTasks { public void unassignServiceInstance(BuildingBlockExecution execution) { try { GeneralBuildingBlock gBBInput = execution.getGeneralBuildingBlock(); - ServiceInstance serviceInstance = extractPojosForBB.extractByKey(execution, ResourceKey.SERVICE_INSTANCE_ID, execution.getLookupMap().get(ResourceKey.SERVICE_INSTANCE_ID)); - - if (serviceInstance.getOrchestrationStatus() == OrchestrationStatus.INVENTORIED) { - return; // If INVENTORIED then SDNC unassign is not necessary - } - + ServiceInstance serviceInstance = extractPojosForBB.extractByKey(execution, ResourceKey.SERVICE_INSTANCE_ID, execution.getLookupMap().get(ResourceKey.SERVICE_INSTANCE_ID)); RequestContext requestContext = gBBInput.getRequestContext(); Customer customer = gBBInput.getCustomer(); String sdncUnassignResponse = sdncSIResources.unassignServiceInstance(serviceInstance, customer, requestContext); @@ -81,13 +74,7 @@ public class SDNCUnassignTasks { ServiceInstance serviceInstance = extractPojosForBB.extractByKey(execution, ResourceKey.SERVICE_INSTANCE_ID, execution.getLookupMap().get(ResourceKey.SERVICE_INSTANCE_ID)); GenericVnf vnf = extractPojosForBB.extractByKey(execution, ResourceKey.GENERIC_VNF_ID, execution.getLookupMap().get(ResourceKey.GENERIC_VNF_ID)); VfModule vfModule = extractPojosForBB.extractByKey(execution, ResourceKey.VF_MODULE_ID, execution.getLookupMap().get(ResourceKey.VF_MODULE_ID)); - - if (OrchestrationStatus.INVENTORIED == vfModule.getOrchestrationStatus() || OrchestrationStatus.PENDING_CREATE == vfModule.getOrchestrationStatus()) { - return; // If INVENTORIED or PENDING_CREATE then SDNC unassign is not necessary - } - execution.setVariable("sdncVfModuleRollback", false); - String response = sdncVfModuleResources.unassignVfModule(vfModule, vnf, serviceInstance); execution.setVariable("SDNCResponse", response); execution.setVariable("sdncVfModuleRollback", true); @@ -101,11 +88,6 @@ public class SDNCUnassignTasks { GeneralBuildingBlock gBBInput = execution.getGeneralBuildingBlock(); ServiceInstance serviceInstance = extractPojosForBB.extractByKey(execution, ResourceKey.SERVICE_INSTANCE_ID, execution.getLookupMap().get(ResourceKey.SERVICE_INSTANCE_ID)); GenericVnf vnf = extractPojosForBB.extractByKey(execution, ResourceKey.GENERIC_VNF_ID, execution.getLookupMap().get(ResourceKey.GENERIC_VNF_ID)); - - if (OrchestrationStatus.INVENTORIED == vnf.getOrchestrationStatus() || OrchestrationStatus.CREATED == vnf.getOrchestrationStatus()) { - return; // If INVENTORIED or CREATED then SDNC unassign is not necessary - } - RequestContext requestContext = gBBInput.getRequestContext(); Customer customer = gBBInput.getCustomer(); CloudRegion cloudRegion = gBBInput.getCloudRegion(); @@ -121,11 +103,6 @@ public class SDNCUnassignTasks { public void unassignNetwork(BuildingBlockExecution execution) throws Exception { GeneralBuildingBlock gBBInput = execution.getGeneralBuildingBlock(); L3Network network = extractPojosForBB.extractByKey(execution, ResourceKey.NETWORK_ID, execution.getLookupMap().get(ResourceKey.NETWORK_ID)); - - if (OrchestrationStatus.INVENTORIED == network.getOrchestrationStatus()) { - return; // If INVENTORIED then SDNC unassign is not necessary - } - ServiceInstance serviceInstance = extractPojosForBB.extractByKey(execution, ResourceKey.SERVICE_INSTANCE_ID, execution.getLookupMap().get(ResourceKey.SERVICE_INSTANCE_ID)); Customer customer = gBBInput.getCustomer(); RequestContext requestContext = gBBInput.getRequestContext(); diff --git a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/namingservice/NamingClient.java b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/namingservice/NamingClient.java new file mode 100644 index 0000000000..f91ad44f2b --- /dev/null +++ b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/namingservice/NamingClient.java @@ -0,0 +1,64 @@ +package org.onap.so.client.namingservice; + +import java.util.ArrayList; +import java.util.List; + +import org.onap.namingservice.model.NameGenDeleteRequest; +import org.onap.namingservice.model.NameGenDeleteResponse; +import org.onap.namingservice.model.NameGenRequest; +import org.onap.namingservice.model.NameGenResponse; +import org.onap.so.client.exception.BadResponseException; +import org.onap.so.logger.MsoLogger; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.core.env.Environment; +import org.springframework.http.HttpEntity; +import org.springframework.http.HttpHeaders; +import org.springframework.http.HttpMethod; +import org.springframework.http.MediaType; +import org.springframework.http.ResponseEntity; +import org.springframework.stereotype.Component; +import org.springframework.web.client.RestTemplate; + + + +@Component +public class NamingClient{ + private static final MsoLogger msoLogger = MsoLogger.getMsoLogger(MsoLogger.Catalog.BPEL, NamingClient.class); + private static final String ENDPOINT = "mso.naming.endpoint"; + private static final String AUTH = "mso.naming.auth"; + + @Autowired + private RestTemplate restTemplate; + @Autowired + private Environment env; + @Autowired + private NamingClientResponseValidator namingClientResponseValidator; + + public String postNameGenRequest(NameGenRequest request) throws BadResponseException { + String targetUrl = env.getProperty(ENDPOINT); + HttpHeaders headers = setHeaders(env.getProperty(AUTH)); + msoLogger.info("Sending postNameGenRequest to url: " + targetUrl); + HttpEntity<NameGenRequest> requestEntity = new HttpEntity<>(request, headers); + ResponseEntity<NameGenResponse> response = restTemplate.postForEntity(targetUrl, requestEntity, NameGenResponse.class); + return namingClientResponseValidator.validateNameGenResponse(response); + } + + public String deleteNameGenRequest(NameGenDeleteRequest request) throws BadResponseException { + String targetUrl = env.getProperty(ENDPOINT); + HttpHeaders headers = setHeaders(env.getProperty(AUTH)); + msoLogger.info("Sending deleteNameGenRequest to url: " + targetUrl); + HttpEntity<NameGenDeleteRequest> requestEntity = new HttpEntity<>(request, headers); + ResponseEntity<NameGenDeleteResponse> response = restTemplate.exchange(targetUrl, HttpMethod.DELETE, requestEntity, NameGenDeleteResponse.class); + return namingClientResponseValidator.validateNameGenDeleteResponse(response); + } + + private HttpHeaders setHeaders(String auth) { + HttpHeaders headers = new HttpHeaders(); + headers.setContentType(MediaType.APPLICATION_JSON); + List<MediaType> acceptableMediaTypes = new ArrayList<>(); + acceptableMediaTypes.add(MediaType.APPLICATION_JSON); + headers.setAccept(acceptableMediaTypes); + headers.add(HttpHeaders.AUTHORIZATION, auth); + return headers; + } +}
\ No newline at end of file diff --git a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/namingservice/NamingClientResponseValidator.java b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/namingservice/NamingClientResponseValidator.java new file mode 100644 index 0000000000..ab0639574c --- /dev/null +++ b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/namingservice/NamingClientResponseValidator.java @@ -0,0 +1,103 @@ +package org.onap.so.client.namingservice; + +import java.util.List; + +import org.apache.http.HttpStatus; +import org.onap.namingservice.model.NameGenDeleteResponse; +import org.onap.namingservice.model.NameGenResponse; +import org.onap.namingservice.model.NameGenResponseError; +import org.onap.namingservice.model.Respelement; +import org.onap.so.client.exception.BadResponseException; +import org.onap.so.logger.MessageEnum; +import org.onap.so.logger.MsoLogger; +import org.springframework.http.ResponseEntity; +import org.springframework.stereotype.Component; + +@Component +public class NamingClientResponseValidator { + private static final MsoLogger msoLogger = MsoLogger.getMsoLogger(MsoLogger.Catalog.BPEL, NamingClientResponseValidator.class); + private static final String INSTANCE_GROUP_NAME = "instance-group-name"; + private static final String NO_RESPONSE_FROM_NAMING_SERVICE = "Error did not receive a response from Naming Service."; + private static final String NULL_RESPONSE_FROM_NAMING_SERVICE = "Error received a null response from Naming Service."; + private static final String NAMING_SERVICE_ERROR = "Error from Naming Service: %s"; + + public String validateNameGenResponse(ResponseEntity<NameGenResponse> response) throws BadResponseException { + if (response == null) { + msoLogger.error(MessageEnum.RA_GENERAL_EXCEPTION, NO_RESPONSE_FROM_NAMING_SERVICE, "BPMN", + MsoLogger.getServiceName(), MsoLogger.ErrorCode.UnknownError, NO_RESPONSE_FROM_NAMING_SERVICE); + throw new BadResponseException(NO_RESPONSE_FROM_NAMING_SERVICE); + } + + int responseCode = response.getStatusCodeValue(); + String generatedName = ""; + NameGenResponse responseBody = response.getBody(); + if (responseBody == null) { + msoLogger.error(MessageEnum.RA_GENERAL_EXCEPTION, NULL_RESPONSE_FROM_NAMING_SERVICE, "BPMN", + MsoLogger.getServiceName(), MsoLogger.ErrorCode.UnknownError, NULL_RESPONSE_FROM_NAMING_SERVICE); + throw new BadResponseException(NULL_RESPONSE_FROM_NAMING_SERVICE); + } + + if (isHttpCodeSuccess(responseCode)) { + msoLogger.info("Successful Response from Naming Service"); + List<Respelement> respList = responseBody.getElements(); + + if (respList != null) { + for (int i=0; i < respList.size(); i++) { + Respelement respElement = respList.get(i); + if (respElement != null) { + String resourceName = respElement.getResourceName(); + if (INSTANCE_GROUP_NAME.equals(resourceName)) { + generatedName = respElement.getResourceValue(); + break; + } + } + } + } + return generatedName; + } else { + NameGenResponseError error = responseBody.getError(); + String errorMessageString = NAMING_SERVICE_ERROR; + if (error != null) { + errorMessageString = error.getMessage(); + } + String errorMessage = String.format(NAMING_SERVICE_ERROR, errorMessageString); + msoLogger.error(MessageEnum.RA_GENERAL_EXCEPTION, errorMessage, "BPMN", MsoLogger.getServiceName(), + MsoLogger.ErrorCode.DataError, errorMessage); + throw new BadResponseException(errorMessage); + } + } + + public String validateNameGenDeleteResponse(ResponseEntity<NameGenDeleteResponse> response) throws BadResponseException { + if (response == null) { + msoLogger.error(MessageEnum.RA_GENERAL_EXCEPTION, NO_RESPONSE_FROM_NAMING_SERVICE, "BPMN", + MsoLogger.getServiceName(), MsoLogger.ErrorCode.UnknownError, NO_RESPONSE_FROM_NAMING_SERVICE); + throw new BadResponseException(NO_RESPONSE_FROM_NAMING_SERVICE); + } + + int responseCode = response.getStatusCodeValue(); + String responseMessage = ""; + NameGenDeleteResponse responseBody = response.getBody(); + if (responseBody == null) { + msoLogger.error(MessageEnum.RA_GENERAL_EXCEPTION, NULL_RESPONSE_FROM_NAMING_SERVICE, "BPMN", + MsoLogger.getServiceName(), MsoLogger.ErrorCode.UnknownError, NULL_RESPONSE_FROM_NAMING_SERVICE); + throw new BadResponseException(NULL_RESPONSE_FROM_NAMING_SERVICE); + } + + if (isHttpCodeSuccess(responseCode)) { + msoLogger.info("Successful Response from Naming Service"); + return responseMessage; + } else { + String errorMessageString = NAMING_SERVICE_ERROR; + + String errorMessage = String.format(NAMING_SERVICE_ERROR, errorMessageString); + msoLogger.error(MessageEnum.RA_GENERAL_EXCEPTION, errorMessage, "BPMN", MsoLogger.getServiceName(), + MsoLogger.ErrorCode.DataError, errorMessage); + throw new BadResponseException(errorMessage); + } + } + + private boolean isHttpCodeSuccess(int code) { + return code >= HttpStatus.SC_OK && code < HttpStatus.SC_MULTIPLE_CHOICES || code == 0; + } + +} diff --git a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/namingservice/NamingRequestObjectBuilder.java b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/namingservice/NamingRequestObjectBuilder.java new file mode 100644 index 0000000000..c3f216e288 --- /dev/null +++ b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/namingservice/NamingRequestObjectBuilder.java @@ -0,0 +1,38 @@ +package org.onap.so.client.namingservice; + +import java.util.List; + +import org.onap.namingservice.model.Deleteelement; +import org.onap.namingservice.model.Element; +import org.onap.namingservice.model.NameGenDeleteRequest; +import org.onap.namingservice.model.NameGenRequest; +import org.springframework.stereotype.Component; + +@Component +public class NamingRequestObjectBuilder{ + + public Element elementMapper(String instanceGroupId, String policyInstanceName, String namingType, String nfNamingCode, String instanceGroupName){ + Element element = new Element(); + element.setExternalKey(instanceGroupId); + element.setPolicyInstanceName(policyInstanceName); + element.setNamingType(namingType); + element.setResourceName(instanceGroupName); + element.setNamingIngredientsZeroOrMore(nfNamingCode); + return element; + } + public Deleteelement deleteElementMapper(String instanceGroupId){ + Deleteelement deleteElement = new Deleteelement(); + deleteElement.setExternalKey(instanceGroupId); + return deleteElement; + } + public NameGenRequest nameGenRequestMapper(List<Element> elements){ + NameGenRequest nameGenRequest = new NameGenRequest(); + nameGenRequest.setElements(elements); + return nameGenRequest; + } + public NameGenDeleteRequest nameGenDeleteRequestMapper(List<Deleteelement> deleteElements){ + NameGenDeleteRequest nameGenDeleteRequest = new NameGenDeleteRequest(); + nameGenDeleteRequest.setElements(deleteElements); + return nameGenDeleteRequest; + } +}
\ No newline at end of file diff --git a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/orchestration/AAIConfigurationResources.java b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/orchestration/AAIConfigurationResources.java index e13a765cf2..a96f01c3d0 100644 --- a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/orchestration/AAIConfigurationResources.java +++ b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/orchestration/AAIConfigurationResources.java @@ -7,9 +7,9 @@ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -38,10 +38,10 @@ import org.springframework.stereotype.Component; public class AAIConfigurationResources { @Autowired private InjectionHelper injectionHelper; - + @Autowired private AAIObjectMapper aaiObjectMapper; - + /** * A&AI call to create configuration * @@ -142,24 +142,32 @@ public class AAIConfigurationResources { * * @param configurationId * @param vpnId + * */ public void connectConfigurationToVpnBinding(String configurationId, String vpnId) { AAIResourceUri configurationURI = AAIUriFactory.createResourceUri(AAIObjectType.CONFIGURATION, configurationId); AAIResourceUri vpnBindingURI = AAIUriFactory.createResourceUri(AAIObjectType.VPN_BINDING, vpnId); injectionHelper.getAaiClient().connect(configurationURI, vpnBindingURI); } - + public void connectConfigurationToVfModule(String configurationId, String vfModuleId, String vnfId){ AAIResourceUri configurationURI = AAIUriFactory.createResourceUri(AAIObjectType.CONFIGURATION, configurationId); AAIResourceUri vfModuleURI = AAIUriFactory.createResourceUri(AAIObjectType.VF_MODULE, vnfId, vfModuleId); injectionHelper.getAaiClient().connect(configurationURI, vfModuleURI); } - + public void connectConfigurationToVnfc(String configurationId, String vnfcName){ AAIResourceUri configurationURI = AAIUriFactory.createResourceUri(AAIObjectType.CONFIGURATION, configurationId); AAIResourceUri vnfcURI = AAIUriFactory.createResourceUri(AAIObjectType.VNFC, vnfcName); injectionHelper.getAaiClient().connect(configurationURI, vnfcURI); } + + public void connectConfigurationToL3Network(String configurationId, String networkId){ + AAIResourceUri configurationURI = AAIUriFactory.createResourceUri(AAIObjectType.CONFIGURATION, configurationId); + AAIResourceUri networkURI = AAIUriFactory.createResourceUri(AAIObjectType.L3_NETWORK, networkId); + injectionHelper.getAaiClient().connect(configurationURI, networkURI); + } + /** * method to delete Configuration details in A&AI * @@ -188,7 +196,7 @@ public class AAIConfigurationResources { return injectionHelper.getAaiClient() .get(org.onap.aai.domain.yang.Configuration.class, AAIUriFactory.createResourceFromExistingURI(AAIObjectType.CONFIGURATION, UriBuilder.fromPath(relatedLink).build())); } - + public void updateOrchestrationStatusConfiguration(Configuration configuration, OrchestrationStatus orchestrationStatus) { AAIResourceUri aaiResourceUri = AAIUriFactory.createResourceUri(AAIObjectType.CONFIGURATION, configuration.getConfigurationId()); configuration.setOrchestrationStatus(orchestrationStatus); diff --git a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/orchestration/AAINetworkResources.java b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/orchestration/AAINetworkResources.java index a4c705b0c7..46b18f5e32 100644 --- a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/orchestration/AAINetworkResources.java +++ b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/orchestration/AAINetworkResources.java @@ -7,9 +7,9 @@ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -47,22 +47,22 @@ import org.springframework.stereotype.Component; public class AAINetworkResources { @Autowired private InjectionHelper injectionHelper; - + @Autowired private AAIObjectMapper aaiObjectMapper; - + public void updateNetwork(L3Network network) { AAIResourceUri networkURI = AAIUriFactory.createResourceUri(AAIObjectType.L3_NETWORK, network.getNetworkId()); org.onap.aai.domain.yang.L3Network aaiL3Network = aaiObjectMapper.mapNetwork(network); injectionHelper.getAaiClient().update(networkURI, aaiL3Network); } - + public void updateSubnet(L3Network network, Subnet subnet) { AAIResourceUri subnetURI = AAIUriFactory.createResourceUri(AAIObjectType.SUBNET, network.getNetworkId(), subnet.getSubnetId()); org.onap.aai.domain.yang.Subnet aaiSubnet = aaiObjectMapper.mapSubnet(subnet); injectionHelper.getAaiClient().update(subnetURI, aaiSubnet); } - + public void createNetworkConnectToServiceInstance(L3Network network, ServiceInstance serviceInstance) { AAIResourceUri networkURI = AAIUriFactory.createResourceUri(AAIObjectType.L3_NETWORK, network.getNetworkId()); network.setOrchestrationStatus(OrchestrationStatus.INVENTORIED); @@ -76,11 +76,11 @@ public class AAINetworkResources { AAIResourceUri networkURI = AAIUriFactory.createResourceUri(AAIObjectType.L3_NETWORK, network.getNetworkId()); injectionHelper.getAaiClient().delete(networkURI); } - + public Optional<VpnBinding> getVpnBinding(AAIResourceUri netBindingUri) { - return injectionHelper.getAaiClient().get(netBindingUri).asBean(VpnBinding.class); + return injectionHelper.getAaiClient().get(netBindingUri.depth(Depth.TWO)).asBean(VpnBinding.class); } - + public Optional<NetworkPolicy> getNetworkPolicy(AAIResourceUri netPolicyUri) { return injectionHelper.getAaiClient().get(netPolicyUri).asBean(NetworkPolicy.class); } @@ -88,85 +88,85 @@ public class AAINetworkResources { public Optional<RouteTableReference> getRouteTable(AAIResourceUri rTableUri) { return injectionHelper.getAaiClient().get(rTableUri).asBean(RouteTableReference.class); } - + public Optional<org.onap.aai.domain.yang.L3Network> queryNetworkById(L3Network l3network) { AAIResourceUri uri = AAIUriFactory.createResourceUri(AAIObjectType.L3_NETWORK,l3network.getNetworkId()).depth(Depth.ALL); AAIResultWrapper aaiWrapper = injectionHelper.getAaiClient().get(uri); return aaiWrapper.asBean(org.onap.aai.domain.yang.L3Network.class); - } - + } + public AAIResultWrapper queryNetworkWrapperById(L3Network l3network) { AAIResourceUri uri = AAIUriFactory.createResourceUri(AAIObjectType.L3_NETWORK,l3network.getNetworkId()).depth(Depth.ALL); return injectionHelper.getAaiClient().get(uri); } - + public void createNetworkInstanceGroup(InstanceGroup instanceGroup) { AAIResourceUri instanceGroupURI = AAIUriFactory.createResourceUri(AAIObjectType.INSTANCE_GROUP, instanceGroup.getId()); org.onap.aai.domain.yang.InstanceGroup aaiInstanceGroup = aaiObjectMapper.mapInstanceGroup(instanceGroup); injectionHelper.getAaiClient().create(instanceGroupURI, aaiInstanceGroup); } - + public void createNetworkCollection(Collection networkCollection) { AAIResourceUri networkCollectionURI = AAIUriFactory.createResourceUri(AAIObjectType.COLLECTION, networkCollection.getId()); networkCollection.setOrchestrationStatus(OrchestrationStatus.INVENTORIED); org.onap.aai.domain.yang.Collection aaiCollection = aaiObjectMapper.mapCollection(networkCollection); injectionHelper.getAaiClient().create(networkCollectionURI, aaiCollection); } - + public void connectNetworkToTenant(L3Network l3network, CloudRegion cloudRegion) { - AAIResourceUri tenantURI = AAIUriFactory.createResourceUri(AAIObjectType.TENANT, + AAIResourceUri tenantURI = AAIUriFactory.createResourceUri(AAIObjectType.TENANT, cloudRegion.getCloudOwner(), cloudRegion.getLcpCloudRegionId(), cloudRegion.getTenantId()); AAIResourceUri networkURI = AAIUriFactory.createResourceUri(AAIObjectType.L3_NETWORK, l3network.getNetworkId()); injectionHelper.getAaiClient().connect(tenantURI, networkURI); } - + public void connectNetworkToCloudRegion(L3Network l3network, CloudRegion cloudRegion) { - AAIResourceUri cloudRegionURI = AAIUriFactory.createResourceUri(AAIObjectType.CLOUD_REGION, + AAIResourceUri cloudRegionURI = AAIUriFactory.createResourceUri(AAIObjectType.CLOUD_REGION, cloudRegion.getCloudOwner(), cloudRegion.getLcpCloudRegionId()); AAIResourceUri networkURI = AAIUriFactory.createResourceUri(AAIObjectType.L3_NETWORK, l3network.getNetworkId()); injectionHelper.getAaiClient().connect(cloudRegionURI, networkURI); } - + public void connectNetworkToNetworkCollectionInstanceGroup(L3Network l3network, InstanceGroup instanceGroup) { AAIResourceUri netwrokCollectionInstanceGroupURI = AAIUriFactory.createResourceUri(AAIObjectType.INSTANCE_GROUP, instanceGroup.getId()); AAIResourceUri networkURI = AAIUriFactory.createResourceUri(AAIObjectType.L3_NETWORK, l3network.getNetworkId()); injectionHelper.getAaiClient().connect(netwrokCollectionInstanceGroupURI, networkURI); } - + public void connectNetworkToNetworkCollectionServiceInstance(L3Network l3network, ServiceInstance networkCollectionServiceInstance) { AAIResourceUri networkCollectionServiceInstanceUri = AAIUriFactory.createResourceUri(AAIObjectType.SERVICE_INSTANCE, networkCollectionServiceInstance.getServiceInstanceId()); AAIResourceUri networkURI = AAIUriFactory.createResourceUri(AAIObjectType.L3_NETWORK, l3network.getNetworkId()); injectionHelper.getAaiClient().connect(networkCollectionServiceInstanceUri, networkURI); } - + public void connectNetworkCollectionInstanceGroupToNetworkCollection(InstanceGroup instanceGroup, Collection networkCollection) { AAIResourceUri networkCollectionUri = AAIUriFactory.createResourceUri(AAIObjectType.COLLECTION, networkCollection.getId()); AAIResourceUri netwrokCollectionInstanceGroupURI = AAIUriFactory.createResourceUri(AAIObjectType.INSTANCE_GROUP, instanceGroup.getId()); injectionHelper.getAaiClient().connect(networkCollectionUri, netwrokCollectionInstanceGroupURI); } - + public void connectInstanceGroupToCloudRegion(InstanceGroup instanceGroup, CloudRegion cloudRegion) { - AAIResourceUri cloudRegionURI = AAIUriFactory.createResourceUri(AAIObjectType.CLOUD_REGION, + AAIResourceUri cloudRegionURI = AAIUriFactory.createResourceUri(AAIObjectType.CLOUD_REGION, cloudRegion.getCloudOwner(), cloudRegion.getLcpCloudRegionId()); AAIResourceUri instanceGroupURI = AAIUriFactory.createResourceUri(AAIObjectType.INSTANCE_GROUP, instanceGroup.getId()); injectionHelper.getAaiClient().connect(instanceGroupURI, cloudRegionURI, AAIEdgeLabel.USES); } - + public void connectNetworkCollectionToServiceInstance(Collection networkCollection, ServiceInstance networkCollectionServiceInstance) { AAIResourceUri networkCollectionUri = AAIUriFactory.createResourceUri(AAIObjectType.COLLECTION, networkCollection.getId()); AAIResourceUri networkCollectionServiceInstanceUri = AAIUriFactory.createResourceUri(AAIObjectType.SERVICE_INSTANCE, networkCollectionServiceInstance.getServiceInstanceId()); injectionHelper.getAaiClient().connect(networkCollectionUri, networkCollectionServiceInstanceUri); } - + public void deleteCollection(Collection collection) { AAIResourceUri collectionURI = AAIUriFactory.createResourceUri(AAIObjectType.COLLECTION, collection.getId()); injectionHelper.getAaiClient().delete(collectionURI); } - + public void deleteNetworkInstanceGroup(InstanceGroup instanceGroup) { AAIResourceUri instanceGroupURI = AAIUriFactory.createResourceUri(AAIObjectType.INSTANCE_GROUP, instanceGroup.getId()); injectionHelper.getAaiClient().delete(instanceGroupURI); } - + } diff --git a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/orchestration/NamingServiceResources.java b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/orchestration/NamingServiceResources.java new file mode 100644 index 0000000000..8b443a165b --- /dev/null +++ b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/orchestration/NamingServiceResources.java @@ -0,0 +1,60 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.onap.so.client.orchestration; + +import java.util.ArrayList; +import java.util.List; + +import org.onap.namingservice.model.Element; +import org.onap.namingservice.model.Deleteelement; +import org.onap.so.bpmn.servicedecomposition.bbobjects.InstanceGroup; +import org.onap.so.client.exception.BadResponseException; +import org.onap.so.client.namingservice.NamingClient; +import org.onap.so.client.namingservice.NamingRequestObjectBuilder; +import org.onap.so.logger.MsoLogger; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; + +@Component +public class NamingServiceResources { + private static final MsoLogger msoLogger = MsoLogger.getMsoLogger(MsoLogger.Catalog.BPEL, NamingServiceResources.class); + private static final String NAMING_TYPE = "instanceGroup"; + + @Autowired + private NamingClient namingClient; + + @Autowired + private NamingRequestObjectBuilder namingRequestObjectBuilder; + + public String generateInstanceGroupName(InstanceGroup instanceGroup, String policyInstanceName, String nfNamingCode) throws BadResponseException { + Element element = namingRequestObjectBuilder.elementMapper(instanceGroup.getId(), policyInstanceName, NAMING_TYPE, nfNamingCode, instanceGroup.getInstanceGroupName()); + List<Element> elements = new ArrayList<Element>(); + elements.add(element); + return(namingClient.postNameGenRequest(namingRequestObjectBuilder.nameGenRequestMapper(elements))); + } + + public String deleteInstanceGroupName(InstanceGroup instanceGroup) throws BadResponseException { + Deleteelement deleteElement = namingRequestObjectBuilder.deleteElementMapper(instanceGroup.getId()); + List<Deleteelement> deleteElements = new ArrayList<Deleteelement>(); + deleteElements.add(deleteElement); + return(namingClient.deleteNameGenRequest(namingRequestObjectBuilder.nameGenDeleteRequestMapper(deleteElements))); + } +} diff --git a/bpmn/so-bpmn-tasks/src/main/resources/naming-service/swagger.json b/bpmn/so-bpmn-tasks/src/main/resources/naming-service/swagger.json new file mode 100644 index 0000000000..b86ffbc6b0 --- /dev/null +++ b/bpmn/so-bpmn-tasks/src/main/resources/naming-service/swagger.json @@ -0,0 +1,325 @@ +{ + "swagger": "2.0", + "info": { + "version": "2018.08.01", + "title": "networkelementnamegenprodtest Service" + }, + "basePath": "/web", + "paths": { + "/service/v1/addPolicy": { + "post": { + "summary": "Respond Hello <name>!", + "description": "Returns a JSON object with a string to say hello. Uses 'world' if a name is not specified", + "operationId": "addPolicyToDB", + "produces": [ + "application/json" + ], + "responses": { + "200": { + "description": "successful operation", + "schema": { + "type": "object", + "additionalProperties": { + "type": "object" + } + } + }, + "404": { + "description": "Service not available" + }, + "500": { + "description": "Unexpected Runtime error" + } + } + } + }, + "/service/v1/genNetworkElementName": { + "post": { + "summary": "Generates name", + "description": "Generates network element name based on a naming policy1 ", + "operationId": "generateNetworkElementName", + "produces": [ + "application/json" + ], + "parameters": [ + { + "in": "body", + "name": "body", + "required": true, + "schema": { + "$ref": "#/definitions/NameGenRequest" + } + } + ], + "responses": { + "200": { + "description": "successful operation", + "schema": { + "$ref": "#/definitions/NameGenResponse" + } + }, + "404": { + "description": "Service not available" + }, + "500": { + "description": "Unexpected Runtime error" + } + } + }, + "delete": { + "summary": "Release an existing name by external key", + "description": "Release network element name ", + "operationId": "releaseNetworkElementName", + "produces": [ + "application/json" + ],"parameters": [ + { + "in": "body", + "name": "body", + "required": true, + "schema": { + "$ref": "#/definitions/NameGenDeleteRequest" + } + } + ], + "responses": { + "200": { + "description": "successful operation", + "schema": { + "$ref": "#/definitions/NameGenDeleteResponse" + } + }, + "404": { + "description": "Service not available" + }, + "500": { + "description": "Unexpected Runtime error" + } + } + } + }, + "/service/v1/getpolicyresponse/{policyName}": { + "get": { + "summary": "Respond Hello <name>!", + "description": "Returns a JSON object with a string to say hello. Uses 'world' if a name is not specified", + "operationId": "getPolicyResponse", + "produces": [ + "application/json" + ], + "responses": { + "200": { + "description": "successful operation", + "schema": { + "type": "object", + "additionalProperties": { + "type": "object" + } + } + }, + "404": { + "description": "Service not available" + }, + "500": { + "description": "Unexpected Runtime error" + } + } + } + } + }, + "definitions": { + "HelloWorld": { + "type": "object", + "properties": { + "message": { + "type": "string" + } + } + }, + "NameGenRequest": { + "title": "NameGenRequest", + "$schema": "http://json-schema.org/draft-07/schema#", + "type": "object", + "required": [ + "elements" + ], + "properties": { + "elements": { + "type": "array", + "items": { + "$ref": "#/definitions/element" + } + } + }, + "additionalProperties": false, + "definitions": { + "element": { + "type": "object", + "required": [ + "resource-name", + "external-key", + "policy-instance-name", + "naming-type" + ], + "properties": { + "resource-name": { + "type": "string", + "description": "Name of the resource" + }, + "resource-value": { + "type": "string", + "description": "Optional. If given, request will be considered as update request" + }, + "external-key": { + "type": "string", + "description": "Key identifier for generated name. This will be used in release/update request" + }, + "policy-instance-name": { + "type": "string", + "description": "Name of the policy to be used for name generation" + }, + "naming-type": { + "type": "string", + "description": "Naming type of the resource" + } + }, + "additionalProperties": { + "type": "string" + } + } + } + }, + "NameGenResponse": { + "type": "object", + "description":"Response with generated names for each naming type. Either elements(one or more) or an error block will be present", + "properties": { + "elements" : { + "type":"array", + "items": { "$ref": "#/definitions/respelement" } + }, + "error" : { + "type":"object", + "required": ["errorId", "message"], + "properties":{ + "errorId":{"type":"string" , "description":"error code"}, + "message": {"type":"string", "description":"error message"} + } + } + } + }, + "element": { + "type": "object", + "required": [ + "resource-name", + "external-key", + "policy-instance-name", + "naming-type" + ], + "properties": { + "resource-name": { + "type": "string", + "description": "Name of the resource" + }, + "resource-value": { + "type": "string", + "description": "Optional. If given, request will be considered as update request" + }, + "external-key": { + "type": "string", + "description": "Key identifier for generated name. This will be used in release/update request" + }, + "policy-instance-name": { + "type": "string", + "description": "Name of the policy to be used for name generation" + }, + "naming-type": { + "type": "string", + "description": "Naming type of the resource" + }, + "${naming-ingredients(zero or more)}": { + "type": "string", + "description": "values to subsitute in the naming recipe" + } + }, + "additionalProperties": { + "type": "string" + } + }, + "respelement": { + "type":"object", + "required": [ "resource-name","resource-value","external-key"], + "properties": { + "resource-value": { + "type": "string", + "description": "Optional. If given, request will be considered as update request" + }, + "resource-name": { + "type": "string", + "description": "Name of the resource" + }, + "external-key": { + "type": "string", + "description": "Key identifier for generated name. This will be used in release/update request" + } + } + }, + "NameGenDeleteRequest": { + "title": "NameGenRequest", + "$schema": "http://json-schema.org/draft-07/schema#", + "type": "object", + "required": [ + "elements" + ], + "properties": { + "elements": { + "type": "array", + "items": { + "$ref": "#/definitions/deleteelement" + } + } + } + }, + "deleteelement": { + "type": "object", + "required": [ "external-key" ], + "properties": { + "external-key": { + "type": "string", + "description": "External key of the name that is being released" + } + } + },"NameGenDeleteResponse": { + "title": "NameGenRequest", + "$schema": "http://json-schema.org/draft-07/schema#", + "type": "object", + "required": [ + "elements" + ], + "properties": { + "elements": { + "type": "array", + "items": { + "$ref": "#/definitions/deleteresponseelement" + } + } + } + }, + "deleteresponseelement": { + "type": "object", + "required": [ "resource-value","resource_name","external-key" ], + "properties": { + "resource-value": { + "type": "string", + "description": "Name that is being release" + }, + "resource-name": { + "type": "string", + "description": "Resource Name" + }, + "external-key": { + "type": "string", + "description": "External key of the name that is being released" + } + } + } + } +}
\ No newline at end of file |