diff options
Diffstat (limited to 'bpmn/so-bpmn-tasks/src/main/java')
8 files changed, 416 insertions, 34 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/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))); + } +} |