summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorIttay Stern <ittay.stern@att.com>2019-12-09 20:06:15 +0200
committerIttay Stern <ittay.stern@att.com>2019-12-09 21:18:49 +0200
commit5540d178ab3203ab2994b21ee3434cca73318aa3 (patch)
treea156a4c63e5f0ce1846ee1a20c5dd4fa12c626fd
parent299190fbe78defb71a717e446c0f394ea7404dfe (diff)
Join ExistingElementsCounterMaps with ServiceInstantiation
This new pretty creature is called "ServiceInstantiationTemplate" :-) Issue-ID: VID-724 Change-Id: I1437d76e79512920079b574844b19368c07f501f Signed-off-by: Ittay Stern <ittay.stern@att.com>
-rw-r--r--vid-app-common/src/main/java/org/onap/vid/controller/AsyncInstantiationController.java13
-rw-r--r--vid-app-common/src/main/java/org/onap/vid/model/aaiTree/ExistingElementsCounterMaps.java34
-rw-r--r--vid-app-common/src/main/java/org/onap/vid/model/aaiTree/ServiceInstance.java6
-rw-r--r--vid-app-common/src/main/java/org/onap/vid/model/serviceInstantiation/ServiceInstantiationTemplate.java81
-rw-r--r--vid-app-common/src/main/java/org/onap/vid/services/AsyncInstantiationBusinessLogic.java2
-rw-r--r--vid-app-common/src/main/java/org/onap/vid/services/AsyncInstantiationBusinessLogicImpl.java5
-rw-r--r--vid-app-common/src/main/java/org/onap/vid/services/InstantiationTemplatesService.java67
-rw-r--r--vid-app-common/src/test/java/org/onap/vid/services/AsyncInstantiationBusinessLogicTest.java12
-rw-r--r--vid-app-common/src/test/java/org/onap/vid/services/InstantiationTemplatesServiceTest.java102
9 files changed, 298 insertions, 24 deletions
diff --git a/vid-app-common/src/main/java/org/onap/vid/controller/AsyncInstantiationController.java b/vid-app-common/src/main/java/org/onap/vid/controller/AsyncInstantiationController.java
index c46266790..96e777a13 100644
--- a/vid-app-common/src/main/java/org/onap/vid/controller/AsyncInstantiationController.java
+++ b/vid-app-common/src/main/java/org/onap/vid/controller/AsyncInstantiationController.java
@@ -36,6 +36,7 @@ import org.onap.vid.properties.Features;
import org.onap.vid.roles.RoleProvider;
import org.onap.vid.services.AsyncInstantiationBusinessLogic;
import org.onap.vid.services.AuditService;
+import org.onap.vid.services.InstantiationTemplatesService;
import org.onap.vid.utils.SystemPropertiesWrapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
@@ -55,6 +56,7 @@ public class AsyncInstantiationController extends VidRestrictedBaseController {
public static final String ASYNC_INSTANTIATION = "asyncInstantiation";
protected final AsyncInstantiationBusinessLogic asyncInstantiationBL;
+ protected final InstantiationTemplatesService instantiationTemplates;
protected final AsyncInstantiationRepository asyncInstantiationRepository;
private final SystemPropertiesWrapper systemPropertiesWrapper;
@@ -62,18 +64,21 @@ public class AsyncInstantiationController extends VidRestrictedBaseController {
private final FeatureManager featureManager;
- @Autowired
- protected AuditService auditService;
+ protected final AuditService auditService;
@Autowired
public AsyncInstantiationController(AsyncInstantiationBusinessLogic asyncInstantiationBL,
+ InstantiationTemplatesService instantiationTemplates,
AsyncInstantiationRepository asyncInstantiationRepository, RoleProvider roleProvider,
- FeatureManager featureManager, SystemPropertiesWrapper systemPropertiesWrapper) {
+ FeatureManager featureManager, SystemPropertiesWrapper systemPropertiesWrapper,
+ AuditService auditService) {
this.asyncInstantiationBL = asyncInstantiationBL;
+ this.instantiationTemplates = instantiationTemplates;
this.asyncInstantiationRepository = asyncInstantiationRepository;
this.roleProvider = roleProvider;
this.featureManager = featureManager;
this.systemPropertiesWrapper = systemPropertiesWrapper;
+ this.auditService = auditService;
}
/**
@@ -171,7 +176,7 @@ public class AsyncInstantiationController extends VidRestrictedBaseController {
@GetMapping("templateTopology/{jobId}")
public ServiceInstantiation getTemplateTopology(HttpServletRequest request, @PathVariable(value="jobId") UUID jobId) {
- return asyncInstantiationBL.getJobRequestAsTemplate(jobId);
+ return instantiationTemplates.getJobRequestAsTemplate(jobId);
}
@RequestMapping(value = "/auditStatusForRetry/{trackById}", method = RequestMethod.GET)
diff --git a/vid-app-common/src/main/java/org/onap/vid/model/aaiTree/ExistingElementsCounterMaps.java b/vid-app-common/src/main/java/org/onap/vid/model/aaiTree/ExistingElementsCounterMaps.java
new file mode 100644
index 000000000..de63c2c94
--- /dev/null
+++ b/vid-app-common/src/main/java/org/onap/vid/model/aaiTree/ExistingElementsCounterMaps.java
@@ -0,0 +1,34 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * VID
+ * ================================================================================
+ * Copyright (C) 2017 - 2019 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.vid.model.aaiTree;
+
+import java.util.Map;
+
+public interface ExistingElementsCounterMaps {
+
+ Map<String, Long> getExistingVNFCounterMap();
+
+ Map<String, Long> getExistingNetworksCounterMap();
+
+ Map<String, Long> getExistingVnfGroupCounterMap();
+
+ Map<String, Long> getExistingVRFCounterMap();
+}
diff --git a/vid-app-common/src/main/java/org/onap/vid/model/aaiTree/ServiceInstance.java b/vid-app-common/src/main/java/org/onap/vid/model/aaiTree/ServiceInstance.java
index 923be132f..78afe1d45 100644
--- a/vid-app-common/src/main/java/org/onap/vid/model/aaiTree/ServiceInstance.java
+++ b/vid-app-common/src/main/java/org/onap/vid/model/aaiTree/ServiceInstance.java
@@ -24,7 +24,7 @@ import java.util.HashMap;
import java.util.Map;
import org.onap.vid.mso.model.ModelInfo;
-public class ServiceInstance extends AbstractNode {
+public class ServiceInstance extends AbstractNode implements ExistingElementsCounterMaps {
private String globalSubscriberId;
private String subscriptionServiceType;
@@ -198,6 +198,7 @@ public class ServiceInstance extends AbstractNode {
this.validationCounter = validationCounter;
}
+ @Override
public Map<String, Long> getExistingVNFCounterMap() {
return existingVNFCounterMap;
}
@@ -206,6 +207,7 @@ public class ServiceInstance extends AbstractNode {
this.existingVNFCounterMap = existingVNFCounterMap;
}
+ @Override
public Map<String, Long> getExistingNetworksCounterMap() {
return existingNetworksCounterMap;
}
@@ -214,6 +216,7 @@ public class ServiceInstance extends AbstractNode {
this.existingNetworksCounterMap = existingNetworksCounterMap;
}
+ @Override
public Map<String, Long> getExistingVnfGroupCounterMap() {
return existingVnfGroupCounterMap;
}
@@ -230,6 +233,7 @@ public class ServiceInstance extends AbstractNode {
this.vrfs = vrfs;
}
+ @Override
public Map<String, Long> getExistingVRFCounterMap() {
return existingVRFCounterMap;
}
diff --git a/vid-app-common/src/main/java/org/onap/vid/model/serviceInstantiation/ServiceInstantiationTemplate.java b/vid-app-common/src/main/java/org/onap/vid/model/serviceInstantiation/ServiceInstantiationTemplate.java
new file mode 100644
index 000000000..17ce1bcc3
--- /dev/null
+++ b/vid-app-common/src/main/java/org/onap/vid/model/serviceInstantiation/ServiceInstantiationTemplate.java
@@ -0,0 +1,81 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * VID
+ * ================================================================================
+ * Copyright (C) 2017 - 2019 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.vid.model.serviceInstantiation;
+
+import java.util.Map;
+import java.util.Objects;
+import org.onap.vid.model.aaiTree.ExistingElementsCounterMaps;
+
+public class ServiceInstantiationTemplate extends ServiceInstantiation implements ExistingElementsCounterMaps {
+
+ private final Map<String, Long> existingVNFCounterMap;
+ private final Map<String, Long> existingNetworksCounterMap;
+ private final Map<String, Long> existingVnfGroupCounterMap;
+ private final Map<String, Long> existingVRFCounterMap;
+
+ public ServiceInstantiationTemplate(
+ ServiceInstantiation baseService,
+ Map<String, Long> vnfCounterMap,
+ Map<String, Long> networksCounterMap,
+ Map<String, Long> vnfGroupCounterMap,
+ Map<String, Long> VRFCounterMap
+ ) {
+ super(
+ baseService.getModelInfo(), baseService.getOwningEntityId(), baseService.getOwningEntityName(),
+ baseService.getProjectName(), baseService.getGlobalSubscriberId(), baseService.getSubscriberName(),
+ baseService.getProductFamilyId(), baseService.getInstanceName(), baseService.getSubscriptionServiceType(),
+ baseService.getLcpCloudRegionId(), baseService.getLcpCloudRegionId(), baseService.getTenantId(),
+ baseService.getTenantName(), baseService.getAicZoneId(), baseService.getAicZoneName(),
+ baseService.getVnfs(), baseService.getNetworks(), baseService.getVnfGroups(), baseService.getVrfs(),
+ baseService.getInstanceParams(), baseService.isPause(), baseService.getBulkSize(),
+ baseService.isRollbackOnFailure(), baseService.isALaCarte(), baseService.getTestApi(),
+ baseService.getInstanceId(), Objects.toString(baseService.getAction(), null),
+ baseService.getTrackById(), baseService.getIsFailed(), baseService.getStatusMessage(),
+ baseService.getVidNotions()
+ );
+
+ this.existingVNFCounterMap = vnfCounterMap;
+ this.existingNetworksCounterMap = networksCounterMap;
+ this.existingVnfGroupCounterMap = vnfGroupCounterMap;
+ this.existingVRFCounterMap = VRFCounterMap;
+ }
+
+ @Override
+ public Map<String, Long> getExistingVNFCounterMap() {
+ return existingVNFCounterMap;
+ }
+
+ @Override
+ public Map<String, Long> getExistingNetworksCounterMap() {
+ return existingNetworksCounterMap;
+ }
+
+ @Override
+ public Map<String, Long> getExistingVnfGroupCounterMap() {
+ return existingVnfGroupCounterMap;
+ }
+
+ @Override
+ public Map<String, Long> getExistingVRFCounterMap() {
+ return existingVRFCounterMap;
+ }
+
+}
diff --git a/vid-app-common/src/main/java/org/onap/vid/services/AsyncInstantiationBusinessLogic.java b/vid-app-common/src/main/java/org/onap/vid/services/AsyncInstantiationBusinessLogic.java
index e00758aa1..bb1121339 100644
--- a/vid-app-common/src/main/java/org/onap/vid/services/AsyncInstantiationBusinessLogic.java
+++ b/vid-app-common/src/main/java/org/onap/vid/services/AsyncInstantiationBusinessLogic.java
@@ -108,7 +108,5 @@ public interface AsyncInstantiationBusinessLogic {
ServiceInstantiation getBulkForRetry(UUID jobId);
- ServiceInstantiation getJobRequestAsTemplate(UUID jobId);
-
String getResumeRequestPath(String requestId);
}
diff --git a/vid-app-common/src/main/java/org/onap/vid/services/AsyncInstantiationBusinessLogicImpl.java b/vid-app-common/src/main/java/org/onap/vid/services/AsyncInstantiationBusinessLogicImpl.java
index 86d630b2a..c77eb8230 100644
--- a/vid-app-common/src/main/java/org/onap/vid/services/AsyncInstantiationBusinessLogicImpl.java
+++ b/vid-app-common/src/main/java/org/onap/vid/services/AsyncInstantiationBusinessLogicImpl.java
@@ -534,11 +534,6 @@ public class AsyncInstantiationBusinessLogicImpl implements
}
@Override
- public ServiceInstantiation getJobRequestAsTemplate(UUID jobId) {
- return asyncInstantiationRepository.getJobRequest(jobId);
- }
-
- @Override
public void addResourceInfo(JobSharedData sharedData, Job.JobStatus jobStatus, String instanceId) {
String trackById = ((BaseResource) sharedData.getRequest()).getTrackById();
ResourceInfo resourceInfo = new ResourceInfo(trackById, sharedData.getRootJobId(), instanceId, jobStatus, null);
diff --git a/vid-app-common/src/main/java/org/onap/vid/services/InstantiationTemplatesService.java b/vid-app-common/src/main/java/org/onap/vid/services/InstantiationTemplatesService.java
new file mode 100644
index 000000000..aa0031104
--- /dev/null
+++ b/vid-app-common/src/main/java/org/onap/vid/services/InstantiationTemplatesService.java
@@ -0,0 +1,67 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * VID
+ * ================================================================================
+ * Copyright (C) 2017 - 2019 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.vid.services;
+
+import static java.util.Collections.emptyMap;
+import static java.util.Objects.requireNonNull;
+
+import java.util.Map;
+import java.util.UUID;
+import javax.inject.Inject;
+import org.onap.vid.dal.AsyncInstantiationRepository;
+import org.onap.vid.model.ModelUtil;
+import org.onap.vid.model.serviceInstantiation.BaseResource;
+import org.onap.vid.model.serviceInstantiation.ServiceInstantiation;
+import org.onap.vid.model.serviceInstantiation.ServiceInstantiationTemplate;
+import org.springframework.stereotype.Component;
+
+@Component
+public class InstantiationTemplatesService {
+
+ private final ModelUtil modelUtil;
+ private final AsyncInstantiationRepository asyncInstantiationRepository;
+
+ @Inject
+ public InstantiationTemplatesService(ModelUtil modelUtil,
+ AsyncInstantiationRepository asyncInstantiationRepository) {
+ this.modelUtil = modelUtil;
+ this.asyncInstantiationRepository = asyncInstantiationRepository;
+ }
+
+ public ServiceInstantiationTemplate getJobRequestAsTemplate(UUID jobId) {
+ ServiceInstantiation jobRequest = requireNonNull(asyncInstantiationRepository.getJobRequest(jobId));
+
+ return new ServiceInstantiationTemplate(
+ jobRequest,
+ counterMap(jobRequest.getVnfs()),
+ counterMap(jobRequest.getNetworks()),
+ counterMap(jobRequest.getVnfGroups()),
+ emptyMap() // model info for VRF is not stored
+ );
+ }
+
+ private <T extends BaseResource> Map<String, Long> counterMap(Map<String, T> nodesToCount) {
+ return modelUtil.getExistingCounterMap(
+ nodesToCount, BaseResource::getModelInfo
+ );
+ }
+
+}
diff --git a/vid-app-common/src/test/java/org/onap/vid/services/AsyncInstantiationBusinessLogicTest.java b/vid-app-common/src/test/java/org/onap/vid/services/AsyncInstantiationBusinessLogicTest.java
index 56aaf1e83..d1124f3a8 100644
--- a/vid-app-common/src/test/java/org/onap/vid/services/AsyncInstantiationBusinessLogicTest.java
+++ b/vid-app-common/src/test/java/org/onap/vid/services/AsyncInstantiationBusinessLogicTest.java
@@ -35,7 +35,6 @@ import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.matchesPattern;
import static org.hamcrest.Matchers.not;
import static org.hamcrest.Matchers.nullValue;
-import static org.hamcrest.Matchers.sameInstance;
import static org.hamcrest.core.Every.everyItem;
import static org.hamcrest.core.IsEqual.equalTo;
import static org.mockito.ArgumentMatchers.any;
@@ -1369,15 +1368,4 @@ public class AsyncInstantiationBusinessLogicTest extends AsyncInstantiationBaseT
}
- @Test
- public void getJobRequestAsTemplate_whenIsCalled_asyncInstantiationRepositoryGetJobRequestIsDelegated() {
- UUID jobId = UUID.randomUUID();
- ServiceInstantiation expected = mock(ServiceInstantiation.class);
- doReturn(expected).when(asyncInstantiationRepository).getJobRequest(jobId);
-
- ServiceInstantiation jobRequestAsTemplate = asyncInstantiationBL.getJobRequestAsTemplate(jobId);
-
- assertThat(jobRequestAsTemplate, is(sameInstance(expected)));
-
- }
}
diff --git a/vid-app-common/src/test/java/org/onap/vid/services/InstantiationTemplatesServiceTest.java b/vid-app-common/src/test/java/org/onap/vid/services/InstantiationTemplatesServiceTest.java
new file mode 100644
index 000000000..f09ea313c
--- /dev/null
+++ b/vid-app-common/src/test/java/org/onap/vid/services/InstantiationTemplatesServiceTest.java
@@ -0,0 +1,102 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * VID
+ * ================================================================================
+ * Copyright (C) 2017 - 2019 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.vid.services;
+
+import static net.javacrumbs.jsonunit.JsonMatchers.jsonEquals;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.anEmptyMap;
+import static org.hamcrest.Matchers.hasProperty;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.Mockito.RETURNS_DEEP_STUBS;
+import static org.mockito.Mockito.doReturn;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+import com.google.common.collect.ImmutableMap;
+import java.util.Map;
+import java.util.UUID;
+import org.mockito.InjectMocks;
+import org.mockito.Mock;
+import org.onap.vid.dal.AsyncInstantiationRepository;
+import org.onap.vid.model.ModelUtil;
+import org.onap.vid.model.serviceInstantiation.ServiceInstantiation;
+import org.onap.vid.model.serviceInstantiation.ServiceInstantiationTemplate;
+import org.onap.vid.model.serviceInstantiation.Vnf;
+import org.onap.vid.testUtils.TestUtils;
+import org.testng.annotations.BeforeMethod;
+import org.testng.annotations.Test;
+
+public class InstantiationTemplatesServiceTest {
+
+ @Mock
+ private AsyncInstantiationRepository asyncInstantiationRepository;
+
+ @Mock
+ private ModelUtil modelUtil;
+
+ @InjectMocks
+ private InstantiationTemplatesService instantiationTemplatesService;
+
+ @BeforeMethod
+ public void initMocks() {
+ TestUtils.initMockitoMocks(this);
+ }
+
+ @Test
+ public void getJobRequestAsTemplate_whenIsCalled_asyncInstantiationRepositoryGetJobRequestIsInvoked() {
+ UUID jobId = UUID.randomUUID();
+ ServiceInstantiation serviceInstantiationMock = mock(ServiceInstantiation.class, RETURNS_DEEP_STUBS);
+ doReturn(serviceInstantiationMock).when(asyncInstantiationRepository).getJobRequest(jobId);
+
+ // When...
+ instantiationTemplatesService.getJobRequestAsTemplate(jobId);
+
+ verify(asyncInstantiationRepository).getJobRequest(jobId);
+ }
+
+ @Test
+ public void getJobRequestAsTemplate_givenModelUtilReturnsValue_thenVnfCounterMapIsPopulatedWithThatValue() {
+ Map<String, Integer> dummyNonEmptyMap = ImmutableMap.of("dummyKey", 9);
+ ServiceInstantiation serviceInstantiation = mock(ServiceInstantiation.class, RETURNS_DEEP_STUBS);
+ doReturn(serviceInstantiation).when(asyncInstantiationRepository).getJobRequest(any());
+
+ // Given...
+ when(modelUtil.getExistingCounterMap(any(), any())).thenAnswer(
+ // return empty counterMap if argument is an empty map; otherwise return a mocked response
+ invocation -> ((Map)invocation.getArgument(0)).size() == 0 // isEmpty() does not work on mocks
+ ? ImmutableMap.of()
+ : dummyNonEmptyMap
+ );
+
+ // only vnf will have a non-empty value
+ when(serviceInstantiation.getVnfs()).thenReturn(ImmutableMap.of("1", mock(Vnf.class)));
+
+ // When...
+ ServiceInstantiationTemplate result = instantiationTemplatesService.getJobRequestAsTemplate(UUID.randomUUID());
+
+ assertThat(result, hasProperty("existingVNFCounterMap", jsonEquals(dummyNonEmptyMap)));
+ assertThat(result, hasProperty("existingNetworksCounterMap", anEmptyMap()));
+ assertThat(result, hasProperty("existingVnfGroupCounterMap", anEmptyMap()));
+ assertThat(result, hasProperty("existingVRFCounterMap", anEmptyMap()));
+ }
+
+}