aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ArtifactsBusinessLogic.java28
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ArtifactBusinessLogicTest.java5
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ArtifactsBusinessLogicTest.java16
-rw-r--r--catalog-model/src/main/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/ToscaOperationFacade.java50
-rw-r--r--catalog-model/src/test/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/ToscaOperationFacadeTest.java10
5 files changed, 31 insertions, 78 deletions
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ArtifactsBusinessLogic.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ArtifactsBusinessLogic.java
index 9f5436d152..c17af4d4de 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ArtifactsBusinessLogic.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ArtifactsBusinessLogic.java
@@ -2513,32 +2513,14 @@ public class ArtifactsBusinessLogic extends BaseBusinessLogic {
}
private Service validateServiceNameAndVersion(String serviceName, String serviceVersion) {
- Either<List<Service>, StorageOperationStatus> serviceListBySystemName = toscaOperationFacade
- .getBySystemName(ComponentTypeEnum.SERVICE, serviceName);
- if (serviceListBySystemName.isRight()) {
+ final Either<Service, StorageOperationStatus> serviceBySystemNameAndVersion
+ = toscaOperationFacade.getBySystemNameAndVersion(ComponentTypeEnum.SERVICE, serviceName, serviceVersion);
+ if (serviceBySystemNameAndVersion.isRight()) {
log.debug("Couldn't fetch any service with name {}", serviceName);
throw new ByActionStatusComponentException(
- componentsUtils.convertFromStorageResponse(serviceListBySystemName.right().value(), ComponentTypeEnum.SERVICE), serviceName);
+ componentsUtils.convertFromStorageResponse(serviceBySystemNameAndVersion.right().value(), ComponentTypeEnum.SERVICE), serviceName);
}
- List<Service> serviceList = serviceListBySystemName.left().value();
- if (serviceList == null || serviceList.isEmpty()) {
- log.debug("Couldn't fetch any service with name {}", serviceName);
- throw new ByActionStatusComponentException(ActionStatus.SERVICE_NOT_FOUND, serviceName);
- }
- Service foundService = null;
- for (Service service : serviceList) {
- if (service.getVersion().equals(serviceVersion)) {
- log.trace("Found service with version {}", serviceVersion);
- foundService = service;
- break;
- }
- }
- if (foundService == null) {
- log.debug("Couldn't find version {} for service {}", serviceVersion, serviceName);
- throw new ByActionStatusComponentException(ActionStatus.COMPONENT_VERSION_NOT_FOUND, ComponentTypeEnum.SERVICE.getValue(),
- serviceVersion);
- }
- return foundService;
+ return serviceBySystemNameAndVersion.left().value();
}
private Resource validateResourceNameAndVersion(String resourceName, String resourceVersion) {
diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ArtifactBusinessLogicTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ArtifactBusinessLogicTest.java
index 616d9e42f9..fdc762ed44 100644
--- a/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ArtifactBusinessLogicTest.java
+++ b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ArtifactBusinessLogicTest.java
@@ -466,10 +466,7 @@ public class ArtifactBusinessLogicTest extends BaseBusinessLogicMock{
DAOArtifactData.setDataAsArray(payload);
Either<DAOArtifactData, CassandraOperationStatus> artifactfromESres = Either.left(DAOArtifactData);
when(artifactCassandraDao.getArtifact(esArtifactId)).thenReturn(artifactfromESres);
- List<org.openecomp.sdc.be.model.Component> serviceList = new ArrayList<>();
- serviceList.add(service);
- Either<List<org.openecomp.sdc.be.model.Component>, StorageOperationStatus> getServiceRes = Either.left(serviceList);
- when(toscaOperationFacade.getBySystemName(ComponentTypeEnum.SERVICE, serviceName)).thenReturn(getServiceRes);
+ when(toscaOperationFacade.getBySystemNameAndVersion(ComponentTypeEnum.SERVICE, serviceName,serviceVersion)).thenReturn(Either.left(service));
byte[] downloadServiceArtifactByNamesRes =
artifactBL.downloadServiceArtifactByNames(serviceName, serviceVersion, artifactName);
assertThat(downloadServiceArtifactByNamesRes !=null &&
diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ArtifactsBusinessLogicTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ArtifactsBusinessLogicTest.java
index c13a46500f..54ccf2bee9 100644
--- a/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ArtifactsBusinessLogicTest.java
+++ b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ArtifactsBusinessLogicTest.java
@@ -728,11 +728,7 @@ public class ArtifactsBusinessLogicTest extends BaseBusinessLogicMock {
DAOArtifactData.setDataAsArray(payload);
Either<DAOArtifactData, CassandraOperationStatus> artifactfromESres = Either.left(DAOArtifactData);
when(artifactCassandraDao.getArtifact(esArtifactId)).thenReturn(artifactfromESres);
- List<org.openecomp.sdc.be.model.Component> serviceList = new ArrayList<>();
- serviceList.add(service);
- Either<List<org.openecomp.sdc.be.model.Component>, StorageOperationStatus> getServiceRes = Either
- .left(serviceList);
- when(toscaOperationFacade.getBySystemName(ComponentTypeEnum.SERVICE, serviceName)).thenReturn(getServiceRes);
+ when(toscaOperationFacade.getBySystemNameAndVersion(ComponentTypeEnum.SERVICE, serviceName, serviceVersion)).thenReturn(Either.left(service));
byte[] downloadServiceArtifactByNamesRes = artifactBL
.downloadServiceArtifactByNames(serviceName, serviceVersion, artifactName);
assertThat(downloadServiceArtifactByNamesRes != null
@@ -2428,19 +2424,15 @@ public class ArtifactsBusinessLogicTest extends BaseBusinessLogicMock {
esArtifactData.setDataAsArray("test".getBytes());
artifactDefinition.setArtifactName(artifactName);
- List<Service> serviceList = new ArrayList<>();
Map<String, ArtifactDefinition> artifacts = new HashMap<>();
artifacts.put(artifactName, artifactDefinition);
-
- serviceList.add(service);
resource.setDeploymentArtifacts(artifacts);
when(toscaOperationFacade.getComponentByNameAndVersion(eq(ComponentTypeEnum.RESOURCE), eq(resourceName), eq(version),
eq(JsonParseFlagEnum.ParseMetadata)))
.thenReturn(Either.left(resource));
- doReturn(Either.left(serviceList)).when(toscaOperationFacade).getBySystemName(eq(ComponentTypeEnum.SERVICE), eq(serviceName));
- when(artifactCassandraDao.getArtifact(any()))
- .thenReturn(Either.left(esArtifactData));
+ doReturn(Either.left(service)).when(toscaOperationFacade).getBySystemNameAndVersion(ComponentTypeEnum.SERVICE, serviceName, version);
+ when(artifactCassandraDao.getArtifact(any())).thenReturn(Either.left(esArtifactData));
byte[] result = artifactBL.downloadRsrcArtifactByNames(serviceName, version, resourceName, version, artifactName);
Assert.assertEquals(esArtifactData.getDataAsArray(), result);
@@ -2455,4 +2447,4 @@ public class ArtifactsBusinessLogicTest extends BaseBusinessLogicMock {
artifactsBusinessLogic.setComponentsUtils(componentsUtils);
return artifactsBusinessLogic;
}
-} \ No newline at end of file
+}
diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/ToscaOperationFacade.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/ToscaOperationFacade.java
index 31aea03a8e..af1749fb34 100644
--- a/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/ToscaOperationFacade.java
+++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/ToscaOperationFacade.java
@@ -848,44 +848,26 @@ public class ToscaOperationFacade {
return getLatestByName(property, nodeName, JsonParseFlagEnum.ParseMetadata, modelName);
}
- public <T extends Component> Either<List<T>, StorageOperationStatus> getBySystemName(ComponentTypeEnum componentType, String systemName) {
- Either<List<T>, StorageOperationStatus> result = null;
- Either<T, StorageOperationStatus> getComponentRes;
- List<T> components = new ArrayList<>();
- List<GraphVertex> componentVertices;
- Map<GraphPropertyEnum, Object> propertiesToMatch = new EnumMap<>(GraphPropertyEnum.class);
- Map<GraphPropertyEnum, Object> propertiesNotToMatch = new EnumMap<>(GraphPropertyEnum.class);
+ public <T extends Component> Either<T, StorageOperationStatus> getBySystemNameAndVersion(final ComponentTypeEnum componentType,
+ final String systemName,
+ final String version) {
+ final Map<GraphPropertyEnum, Object> propertiesToMatch = new EnumMap<>(GraphPropertyEnum.class);
+ final Map<GraphPropertyEnum, Object> propertiesNotToMatch = new EnumMap<>(GraphPropertyEnum.class);
propertiesToMatch.put(GraphPropertyEnum.SYSTEM_NAME, systemName);
+ propertiesToMatch.put(GraphPropertyEnum.VERSION, version);
if (componentType != null) {
propertiesToMatch.put(GraphPropertyEnum.COMPONENT_TYPE, componentType.name());
}
propertiesNotToMatch.put(GraphPropertyEnum.IS_DELETED, true);
- Either<List<GraphVertex>, JanusGraphOperationStatus> getComponentsRes = janusGraphDao
- .getByCriteria(null, propertiesToMatch, propertiesNotToMatch, JsonParseFlagEnum.ParseAll);
- if (getComponentsRes.isRight()) {
- JanusGraphOperationStatus status = getComponentsRes.right().value();
- log.debug("Failed to fetch the component with system name {}. Status is {} ", systemName, status);
- result = Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
- }
- if (result == null) {
- componentVertices = getComponentsRes.left().value();
- for (GraphVertex componentVertex : componentVertices) {
- getComponentRes = getToscaElementByOperation(componentVertex);
- if (getComponentRes.isRight()) {
- log.debug("Failed to get the component {}. Status is {} ", componentVertex.getJsonMetadataField(JsonPresentationFields.NAME),
- getComponentRes.right().value());
- result = Either.right(getComponentRes.right().value());
- break;
- }
- T componentBySystemName = getComponentRes.left().value();
- log.debug("Found component, id: {}", componentBySystemName.getUniqueId());
- components.add(componentBySystemName);
- }
- }
- if (result == null) {
- result = Either.left(components);
+
+ final Either<List<GraphVertex>, JanusGraphOperationStatus> getResourceResult
+ = janusGraphDao.getByCriteria(null, propertiesToMatch, propertiesNotToMatch,JsonParseFlagEnum.ParseAll);
+ if (getResourceResult.isRight()) {
+ final JanusGraphOperationStatus status = getResourceResult.right().value();
+ log.debug("Failed to find resource with systemName {}, version {}. Status is {} ", systemName, version, status);
+ return Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
}
- return result;
+ return getToscaElementByOperation(getResourceResult.left().value().get(0));
}
public <T extends Component> Either<T, StorageOperationStatus> getComponentByNameAndVersion(ComponentTypeEnum componentType, String name,
@@ -895,7 +877,6 @@ public class ToscaOperationFacade {
public <T extends Component> Either<T, StorageOperationStatus> getComponentByNameAndVersion(ComponentTypeEnum componentType, String name,
String version, JsonParseFlagEnum parseFlag) {
- Either<T, StorageOperationStatus> result;
Map<GraphPropertyEnum, Object> hasProperties = new EnumMap<>(GraphPropertyEnum.class);
Map<GraphPropertyEnum, Object> hasNotProperties = new EnumMap<>(GraphPropertyEnum.class);
hasProperties.put(GraphPropertyEnum.NAME, name);
@@ -909,8 +890,7 @@ public class ToscaOperationFacade {
if (getResourceRes.isRight()) {
JanusGraphOperationStatus status = getResourceRes.right().value();
log.debug("failed to find resource with name {}, version {}. Status is {} ", name, version, status);
- result = Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
- return result;
+ return Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
}
return getToscaElementByOperation(getResourceRes.left().value().get(0));
}
diff --git a/catalog-model/src/test/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/ToscaOperationFacadeTest.java b/catalog-model/src/test/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/ToscaOperationFacadeTest.java
index 8aa4353266..f32c5e2842 100644
--- a/catalog-model/src/test/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/ToscaOperationFacadeTest.java
+++ b/catalog-model/src/test/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/ToscaOperationFacadeTest.java
@@ -649,9 +649,10 @@ class ToscaOperationFacadeTest {
}
@Test
- void testGetBySystemName() {
- Either<List<Component>, StorageOperationStatus> result;
+ void testGetBySystemNameAndVersion() {
+ Either<Component, StorageOperationStatus> result;
String sysName = "sysName";
+ String version = "version";
ComponentTypeEnum componentTypeEnum = ComponentTypeEnum.RESOURCE;
ToscaElement toscaElement = getToscaElementForTest();
List<GraphVertex> componentVertices = new ArrayList<>();
@@ -662,6 +663,7 @@ class ToscaOperationFacadeTest {
propertiesToMatch.put(GraphPropertyEnum.SYSTEM_NAME, sysName);
propertiesToMatch.put(GraphPropertyEnum.COMPONENT_TYPE, componentTypeEnum.name());
+ propertiesToMatch.put(GraphPropertyEnum.VERSION, version);
propertiesNotToMatch.put(GraphPropertyEnum.IS_DELETED, true);
@@ -669,9 +671,9 @@ class ToscaOperationFacadeTest {
.thenReturn(Either.left(componentVertices));
when(topologyTemplateOperationMock.getToscaElement(any(GraphVertex.class), any(ComponentParametersView.class)))
.thenReturn(Either.left(toscaElement));
- result = testInstance.getBySystemName(componentTypeEnum, sysName);
+ result = testInstance.getBySystemNameAndVersion(componentTypeEnum, sysName, version);
assertTrue(result.isLeft());
- assertEquals(1, result.left().value().size());
+ assertNotNull(result.left().value());
}
@Test