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;
public static final String ASYNC_INSTANTIATION = "asyncInstantiation";
protected final AsyncInstantiationBusinessLogic asyncInstantiationBL;
+ protected final InstantiationTemplatesService instantiationTemplates;
protected final AsyncInstantiationRepository asyncInstantiationRepository;
private final SystemPropertiesWrapper systemPropertiesWrapper;
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;
}
/**
@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)
--- /dev/null
+/*-
+ * ============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();
+}
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;
this.validationCounter = validationCounter;
}
+ @Override
public Map<String, Long> getExistingVNFCounterMap() {
return existingVNFCounterMap;
}
this.existingVNFCounterMap = existingVNFCounterMap;
}
+ @Override
public Map<String, Long> getExistingNetworksCounterMap() {
return existingNetworksCounterMap;
}
this.existingNetworksCounterMap = existingNetworksCounterMap;
}
+ @Override
public Map<String, Long> getExistingVnfGroupCounterMap() {
return existingVnfGroupCounterMap;
}
this.vrfs = vrfs;
}
+ @Override
public Map<String, Long> getExistingVRFCounterMap() {
return existingVRFCounterMap;
}
--- /dev/null
+/*-
+ * ============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;
+ }
+
+}
ServiceInstantiation getBulkForRetry(UUID jobId);
- ServiceInstantiation getJobRequestAsTemplate(UUID jobId);
-
String getResumeRequestPath(String requestId);
}
return enrichBulkForRetry( asyncInstantiationRepository.getJobRequest(jobId), jobId);
}
- @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();
--- /dev/null
+/*-
+ * ============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
+ );
+ }
+
+}
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;
}
- @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)));
-
- }
}
--- /dev/null
+/*-
+ * ============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()));
+ }
+
+}