diff options
Diffstat (limited to 'mso-catalog-db')
8 files changed, 291 insertions, 14 deletions
diff --git a/mso-catalog-db/src/main/java/org/onap/so/db/catalog/beans/BBNameSelectionReference.java b/mso-catalog-db/src/main/java/org/onap/so/db/catalog/beans/BBNameSelectionReference.java new file mode 100644 index 0000000000..9b71c970a7 --- /dev/null +++ b/mso-catalog-db/src/main/java/org/onap/so/db/catalog/beans/BBNameSelectionReference.java @@ -0,0 +1,115 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 2019 Tech Mahindra + * ================================================================================ + * 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.db.catalog.beans; + +import java.io.Serializable; +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; +import javax.persistence.Table; +import org.apache.commons.lang3.builder.EqualsBuilder; +import org.apache.commons.lang3.builder.HashCodeBuilder; +import org.apache.commons.lang3.builder.ToStringBuilder; +import com.openpojo.business.annotation.BusinessKey; + +@Entity +@Table(name = "bbname_selection_reference") +public class BBNameSelectionReference implements Serializable { + + private static final long serialVersionUID = 1L; + + @Id + @Column(name = "ID", nullable = false, updatable = false) + @GeneratedValue(strategy = GenerationType.IDENTITY) + private Integer ID; + + @BusinessKey + @Column(name = "CONTROLLER_ACTOR") + private String controllerActor; + + @Column(name = "SCOPE") + private String scope; + + @Column(name = "ACTION") + private String action; + + @BusinessKey + @Column(name = "BB_NAME") + private String bbName; + + public String getControllerActor() { + return controllerActor; + } + + public void setControllerActor(String controllerActor) { + this.controllerActor = controllerActor; + } + + public String getScope() { + return scope; + } + + public void setScope(String scope) { + this.scope = scope; + } + + public String getAction() { + return action; + } + + public void setAction(String action) { + this.action = action; + } + + public Integer getID() { + return ID; + } + + public String getBbName() { + return bbName; + } + + public void setBbName(String bbName) { + this.bbName = bbName; + } + + @Override + public String toString() { + return new ToStringBuilder(this).append("ID", ID).append("controllerActor", controllerActor) + .append("scope", scope).append("action", action).append("bbName", bbName).toString(); + } + + @Override + public boolean equals(final Object other) { + if (!(other instanceof BBNameSelectionReference)) { + return false; + } + BBNameSelectionReference castOther = (BBNameSelectionReference) other; + return new EqualsBuilder().append(controllerActor, castOther.controllerActor).isEquals(); + } + + @Override + public int hashCode() { + return new HashCodeBuilder().append(controllerActor).append(bbName).toHashCode(); + } +} diff --git a/mso-catalog-db/src/main/java/org/onap/so/db/catalog/client/CatalogDbClient.java b/mso-catalog-db/src/main/java/org/onap/so/db/catalog/client/CatalogDbClient.java index 7f5907e9bf..26c33941ed 100644 --- a/mso-catalog-db/src/main/java/org/onap/so/db/catalog/client/CatalogDbClient.java +++ b/mso-catalog-db/src/main/java/org/onap/so/db/catalog/client/CatalogDbClient.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. @@ -32,6 +32,7 @@ import javax.ws.rs.core.UriBuilder; import org.apache.http.HttpStatus; import org.onap.logging.filter.base.Constants; import org.onap.logging.filter.spring.SpringClientPayloadFilter; +import org.onap.so.db.catalog.beans.BBNameSelectionReference; import org.onap.so.db.catalog.beans.BuildingBlockDetail; import org.onap.so.db.catalog.beans.CloudSite; import org.onap.so.db.catalog.beans.CloudifyManager; @@ -119,6 +120,7 @@ public class CatalogDbClient { private static final String PNF_RESOURCE = "/pnfResource"; private static final String PNF_RESOURCE_CUSTOMIZATION = "/pnfResourceCustomization"; private static final String WORKFLOW = "/workflow"; + private static final String BB_NAME_SELECTION_REFERENCE = "/bbNameSelectionReference"; private static final String SEARCH = "/search"; @@ -156,6 +158,7 @@ public class CatalogDbClient { protected static final String HOMING_INSTANCE = "/homingInstance"; protected static final String ARTIFACT_UUID = "artifactUUID"; protected static final String SOURCE = "source"; + protected static final String RESOURCE_TARGET = "resource_target"; private static final String TARGET_ENTITY = "SO:CatalogDB"; private static final String ASTERISK = "*"; @@ -201,10 +204,13 @@ public class CatalogDbClient { private String findServiceByServiceInstanceId = "/findServiceByServiceInstanceId"; private String findPnfResourceCustomizationByModelUuid = "/findPnfResourceCustomizationByModelUuid"; private String findWorkflowByArtifactUUID = "/findByArtifactUUID"; - private String findWorkflowByModelUUID = "/findWorkflowByModelUUID"; + private String findWorkflowByVnfModelUUID = "/findWorkflowByVnfModelUUID"; private String findWorkflowByPnfModelUUID = "/findWorkflowByPnfModelUUID"; private String findWorkflowBySource = "/findBySource"; private String findVnfResourceCustomizationByModelUuid = "/findVnfResourceCustomizationByModelUuid"; + private String findBBNameSelectionReferenceByControllerActorAndScopeAndAction = + "/findBBNameSelectionReferenceByControllerActorAndScopeAndAction"; + private String findWorkflowByResourceTarget = "/findByResourceTarget"; private String serviceURI; private String vfModuleURI; @@ -277,6 +283,8 @@ public class CatalogDbClient { private final Client<Workflow> workflowClient; + private final Client<BBNameSelectionReference> bbNameSelectionReferenceClient; + @Value("${mso.catalog.db.spring.endpoint:#{null}}") private String endpoint; @@ -339,13 +347,17 @@ public class CatalogDbClient { endpoint + PNF_RESOURCE_CUSTOMIZATION + SEARCH + findPnfResourceCustomizationByModelUuid; findWorkflowByArtifactUUID = endpoint + WORKFLOW + SEARCH + findWorkflowByArtifactUUID; - findWorkflowByModelUUID = endpoint + WORKFLOW + SEARCH + findWorkflowByModelUUID; + findWorkflowByVnfModelUUID = endpoint + WORKFLOW + SEARCH + findWorkflowByVnfModelUUID; findWorkflowByPnfModelUUID = endpoint + WORKFLOW + SEARCH + findWorkflowByPnfModelUUID; findWorkflowBySource = endpoint + WORKFLOW + SEARCH + findWorkflowBySource; + findWorkflowByResourceTarget = endpoint + WORKFLOW + SEARCH + findWorkflowByResourceTarget; findVnfResourceCustomizationByModelUuid = endpoint + VNF_RESOURCE_CUSTOMIZATION + SEARCH + findVnfResourceCustomizationByModelUuid; + findBBNameSelectionReferenceByControllerActorAndScopeAndAction = endpoint + BB_NAME_SELECTION_REFERENCE + SEARCH + + findBBNameSelectionReferenceByControllerActorAndScopeAndAction; + serviceURI = endpoint + SERVICE + URI_SEPARATOR; vfModuleURI = endpoint + VFMODULE + URI_SEPARATOR; vnfResourceURI = endpoint + VNF_RESOURCE + URI_SEPARATOR; @@ -412,6 +424,8 @@ public class CatalogDbClient { pnfResourceClient = clientFactory.create(PnfResource.class); pnfResourceCustomizationClient = clientFactory.create(PnfResourceCustomization.class); workflowClient = clientFactory.create(Workflow.class); + bbNameSelectionReferenceClient = clientFactory.create(BBNameSelectionReference.class); + } public CatalogDbClient(String baseUri, String auth) { @@ -462,6 +476,7 @@ public class CatalogDbClient { pnfResourceClient = clientFactory.create(PnfResource.class); pnfResourceCustomizationClient = clientFactory.create(PnfResourceCustomization.class); workflowClient = clientFactory.create(Workflow.class); + bbNameSelectionReferenceClient = clientFactory.create(BBNameSelectionReference.class); } public NetworkCollectionResourceCustomization getNetworkCollectionResourceCustomizationByID( @@ -689,6 +704,14 @@ public class CatalogDbClient { UriBuilder.fromUri(findFirstByModelNameURI).queryParam(MODEL_NAME, modelName).build()); } + public BBNameSelectionReference getBBNameSelectionReference(String controllerActor, String scope, String action) { + + return this.getSingleResource(bbNameSelectionReferenceClient, + getUri(UriBuilder.fromUri(findBBNameSelectionReferenceByControllerActorAndScopeAndAction) + .queryParam("CONTROLLER_ACTOR", controllerActor).queryParam("SCOPE", scope) + .queryParam("ACTION", action).build().toString())); + } + public ExternalServiceToInternalService findExternalToInternalServiceByServiceName(String serviceName) { return this.getSingleResource(externalServiceToInternalServiceClient, getUri(UriBuilder.fromUri(findExternalToInternalServiceByServiceName) @@ -764,8 +787,61 @@ public class CatalogDbClient { return this.getSingleResource(cloudSiteClient, getUri(uri + id)); } - public void postCloudSite(CloudSite cloudSite) { - this.postSingleResource(cloudSiteClient, cloudSite); + public CloudSite postCloudSite(CloudSite cloudSite) { + if (cloudSite == null) { + throw new EntityNotFoundException("CloudSite passed as null"); + } + try { + HttpHeaders headers = getHttpHeaders(); + HttpEntity<CloudSite> entity = new HttpEntity<>(cloudSite, headers); + CloudSite updatedCloudSite = restTemplate + .exchange(UriComponentsBuilder.fromUriString(endpoint + "/cloudSite").build().encode().toString(), + HttpMethod.POST, entity, CloudSite.class) + .getBody(); + return updatedCloudSite; + } catch (HttpClientErrorException e) { + if (HttpStatus.SC_NOT_FOUND == e.getStatusCode().value()) { + throw new EntityNotFoundException("Unable to find CloudSite with Cloud Site Id: " + cloudSite.getId()); + } + throw e; + } + } + + public CloudSite updateCloudSite(CloudSite cloudSite) { + if (cloudSite == null) { + throw new EntityNotFoundException("CloudSite passed as null"); + } + try { + HttpHeaders headers = getHttpHeaders(); + HttpEntity<CloudSite> entity = new HttpEntity<>(cloudSite, headers); + CloudSite updatedCloudSite = restTemplate + .exchange(UriComponentsBuilder.fromUriString(endpoint + "/cloudSite/" + cloudSite.getId()).build() + .encode().toString(), HttpMethod.PUT, entity, CloudSite.class) + .getBody(); + return updatedCloudSite; + } catch (HttpClientErrorException e) { + if (HttpStatus.SC_NOT_FOUND == e.getStatusCode().value()) { + throw new EntityNotFoundException("Unable to find CloudSite with Cloud Site Id: " + cloudSite.getId()); + } + throw e; + } + } + + public void deleteCloudSite(String cloudSiteId) { + if (cloudSiteId == null) { + throw new EntityNotFoundException("CloudSiteId passed as null"); + } + try { + HttpHeaders headers = getHttpHeaders(); + HttpEntity<String> entity = new HttpEntity<>(null, headers); + restTemplate.exchange(UriComponentsBuilder.fromUriString(endpoint + "/cloudSite/" + cloudSiteId).build() + .encode().toString(), HttpMethod.DELETE, entity, CloudSite.class).getBody(); + } catch (HttpClientErrorException e) { + if (HttpStatus.SC_NOT_FOUND == e.getStatusCode().value()) { + throw new EntityNotFoundException("Unable to find CloudSite with Cloud Site Id: " + cloudSiteId); + } + throw e; + } } public List<CloudSite> getCloudSites() { @@ -996,8 +1072,8 @@ public class CatalogDbClient { .queryParam(ARTIFACT_UUID, artifactUUID).build().toString())); } - public List<Workflow> findWorkflowByModelUUID(String vnfResourceModelUUID) { - return this.getMultipleResources(workflowClient, getUri(UriBuilder.fromUri(findWorkflowByModelUUID) + public List<Workflow> findWorkflowByVnfModelUUID(String vnfResourceModelUUID) { + return this.getMultipleResources(workflowClient, getUri(UriBuilder.fromUri(findWorkflowByVnfModelUUID) .queryParam(VNF_RESOURCE_MODEL_UUID, vnfResourceModelUUID).build().toString())); } @@ -1011,6 +1087,11 @@ public class CatalogDbClient { getUri(UriBuilder.fromUri(findWorkflowBySource).queryParam(SOURCE, source).build().toString())); } + public List<Workflow> findWorkflowByResourceTarget(String resourceTarget) { + return this.getMultipleResources(workflowClient, getUri(UriBuilder.fromUri(findWorkflowByResourceTarget) + .queryParam(RESOURCE_TARGET, resourceTarget).build().toString())); + } + public String getEndpoint() { return endpoint; } diff --git a/mso-catalog-db/src/main/java/org/onap/so/db/catalog/data/repository/BBNameSelectionReferenceRepository.java b/mso-catalog-db/src/main/java/org/onap/so/db/catalog/data/repository/BBNameSelectionReferenceRepository.java new file mode 100644 index 0000000000..38f1291f37 --- /dev/null +++ b/mso-catalog-db/src/main/java/org/onap/so/db/catalog/data/repository/BBNameSelectionReferenceRepository.java @@ -0,0 +1,36 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 2019 Tech Mahindra + * ================================================================================ + * 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.db.catalog.data.repository; + + +import org.onap.so.db.catalog.beans.BBNameSelectionReference; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.repository.query.Param; +import org.springframework.data.rest.core.annotation.RepositoryRestResource; + + +@RepositoryRestResource(collectionResourceRel = "bbNameSelectionReference", path = "bbNameSelectionReference") +public interface BBNameSelectionReferenceRepository extends JpaRepository<BBNameSelectionReference, Integer> { + + public BBNameSelectionReference findBBNameSelectionReferenceByControllerActorAndScopeAndAction( + @Param("CONTROLLER_ACTOR") String controllerActor, @Param("SCOPE") String scope, + @Param("ACTION") String action); +} diff --git a/mso-catalog-db/src/main/java/org/onap/so/db/catalog/data/repository/WorkflowRepository.java b/mso-catalog-db/src/main/java/org/onap/so/db/catalog/data/repository/WorkflowRepository.java index f1b399325e..93ec54a2eb 100644 --- a/mso-catalog-db/src/main/java/org/onap/so/db/catalog/data/repository/WorkflowRepository.java +++ b/mso-catalog-db/src/main/java/org/onap/so/db/catalog/data/repository/WorkflowRepository.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. @@ -33,18 +33,20 @@ public interface WorkflowRepository extends JpaRepository<Workflow, Integer> { List<Workflow> findBySource(String source); + List<Workflow> findByResourceTarget(String resourceTarget); + /** * Used to fetch the @{link Workflow} by the Model UUID. * * This operation is required by {@link org.onap.so.db.catalog.client.CatalogDbClient} to provide Workflow based on - * model UUID without projection. + * vnf model UUID without projection. * * @param vnfResourceModelUUID UUID * @return List of Workflow */ @Query(value = "select b.* from vnf_resource_to_workflow a join workflow b where a.WORKFLOW_ID = b.ID and a.VNF_RESOURCE_MODEL_UUID = ?1", nativeQuery = true) - List<Workflow> findWorkflowByModelUUID(String vnfResourceModelUUID); + List<Workflow> findWorkflowByVnfModelUUID(String vnfResourceModelUUID); /** * Used to fetch the @{link Workflow} by the Pnf Model UUID. diff --git a/mso-catalog-db/src/test/java/org/onap/so/db/catalog/client/CatalogDbClientTest.java b/mso-catalog-db/src/test/java/org/onap/so/db/catalog/client/CatalogDbClientTest.java index 66fc0f5dc5..79e3cbcc08 100644 --- a/mso-catalog-db/src/test/java/org/onap/so/db/catalog/client/CatalogDbClientTest.java +++ b/mso-catalog-db/src/test/java/org/onap/so/db/catalog/client/CatalogDbClientTest.java @@ -4,6 +4,8 @@ * ================================================================================ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. * ================================================================================ + * Modifications Copyright (c) 2020 Nordix + * ================================================================================ * 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 @@ -179,7 +181,7 @@ public class CatalogDbClientTest { } @Test - public final void testFindWorkflowByPnfModelUUID() throws Exception { + public final void testFindWorkflowByPnfModelUUID() { String pnfResourceModelUUID = "f2d1f2b2-88bb-49da-b716-36ae420ccbff"; doReturn(new ArrayList()).when(catalogDbClient).getMultipleResources(any(), any()); @@ -190,4 +192,16 @@ public class CatalogDbClientTest { } + @Test + public final void testFindWorkflowByResourceTarget() { + // when + final String pnf_resource = "pnf"; + doReturn(new ArrayList()).when(catalogDbClient).getMultipleResources(any(), any()); + catalogDbClient.findWorkflowByResourceTarget(pnf_resource); + + // verify + verify(catalogDbClient).getMultipleResources(any(Client.class), eq(UriBuilder.fromUri("/findByResourceTarget") + .queryParam(CatalogDbClient.RESOURCE_TARGET, pnf_resource).build())); + } + } diff --git a/mso-catalog-db/src/test/java/org/onap/so/db/catalog/data/repository/WorkflowRepositoryTest.java b/mso-catalog-db/src/test/java/org/onap/so/db/catalog/data/repository/WorkflowRepositoryTest.java index 7d1b8d0d96..e47c61d8b4 100644 --- a/mso-catalog-db/src/test/java/org/onap/so/db/catalog/data/repository/WorkflowRepositoryTest.java +++ b/mso-catalog-db/src/test/java/org/onap/so/db/catalog/data/repository/WorkflowRepositoryTest.java @@ -36,7 +36,8 @@ public class WorkflowRepositoryTest extends BaseTest { @Test public void findByVnfResourceModelUUIDTest() throws Exception { - List<Workflow> workflows = workflowRepository.findWorkflowByModelUUID("ff2ae348-214a-11e7-93ae-92361f002671"); + List<Workflow> workflows = + workflowRepository.findWorkflowByVnfModelUUID("ff2ae348-214a-11e7-93ae-92361f002671"); Assert.assertTrue(workflows != null); Assert.assertTrue(workflows.size() != 0); @@ -54,4 +55,14 @@ public class WorkflowRepositoryTest extends BaseTest { Assert.assertTrue("testingWorkflow.bpmn".equals(workflows.get(0).getArtifactName())); } + @Test + public void findByResourceTargetTest() { + List<Workflow> workflows = workflowRepository.findByResourceTarget("pnf"); + + Assert.assertTrue(workflows != null); + Assert.assertTrue(workflows.size() == 1); + + Assert.assertTrue("DummyPnfWorkflow".equals(workflows.get(0).getArtifactName())); + } + } diff --git a/mso-catalog-db/src/test/resources/data.sql b/mso-catalog-db/src/test/resources/data.sql index e5963c183f..0852aa026d 100644 --- a/mso-catalog-db/src/test/resources/data.sql +++ b/mso-catalog-db/src/test/resources/data.sql @@ -957,3 +957,9 @@ VALUES (select ID from user_parameters where NAME='existing_software_version')), ((select ID from activity_spec where NAME='VNFUpgradeSoftwareActivity' and VERSION=1.0), (select ID from user_parameters where NAME='new_software_version')); + +INSERT INTO bbname_selection_reference (CONTROLLER_ACTOR,SCOPE,ACTION,BB_NAME) +VALUES +('APPC', 'vfModule', 'healthCheck','GenericVnfHealthCheckBB'), +('APPC', 'vfModule', 'configScaleOut','ConfigurationScaleOutBB'), +('APPC', 'vnf', 'healthCheck','GenericVnfHealthCheckBB');
\ No newline at end of file diff --git a/mso-catalog-db/src/test/resources/schema.sql b/mso-catalog-db/src/test/resources/schema.sql index 9037e431d4..6573def570 100644 --- a/mso-catalog-db/src/test/resources/schema.sql +++ b/mso-catalog-db/src/test/resources/schema.sql @@ -1387,6 +1387,18 @@ CREATE TABLE IF NOT EXISTS `activity_spec_to_user_parameters` ( ENGINE = InnoDB DEFAULT CHARACTER SET = latin1; +-- +-- Table structure for table `bbname_selection_reference` +-- +DROP TABLE IF EXISTS `bbname_selection_reference`; +CREATE TABLE IF NOT EXISTS `bbname_selection_reference` ( + `ID` INT(11) NOT NULL AUTO_INCREMENT, + `CONTROLLER_ACTOR` varchar(200) NOT NULL , + `SCOPE` varchar(200) NOT NULL, + `ACTION` varchar(200) NOT NULL, + `BB_NAME` varchar(200) NOT NULL, + PRIMARY KEY (`ID`) +) ENGINE=InnoDB DEFAULT CHARSET=latin1; |