aboutsummaryrefslogtreecommitdiffstats
path: root/vid-app-common/src/main/java
diff options
context:
space:
mode:
Diffstat (limited to 'vid-app-common/src/main/java')
-rw-r--r--vid-app-common/src/main/java/org/onap/vid/controller/AsyncInstantiationController.java11
-rw-r--r--vid-app-common/src/main/java/org/onap/vid/controller/InstantiationTemplatesController.java60
-rw-r--r--vid-app-common/src/main/java/org/onap/vid/model/ServiceInfo.java32
-rw-r--r--vid-app-common/src/main/java/org/onap/vid/services/AsyncInstantiationBusinessLogicImpl.java38
-rw-r--r--vid-app-common/src/main/java/org/onap/vid/utils/DaoUtils.java51
5 files changed, 163 insertions, 29 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 c73a01877..3260656ff 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,10 +36,8 @@ 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;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
@@ -56,7 +54,6 @@ 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;
@@ -68,12 +65,10 @@ public class AsyncInstantiationController extends VidRestrictedBaseController {
@Autowired
public AsyncInstantiationController(AsyncInstantiationBusinessLogic asyncInstantiationBL,
- InstantiationTemplatesService instantiationTemplates,
AsyncInstantiationRepository asyncInstantiationRepository, RoleProvider roleProvider,
FeatureManager featureManager, SystemPropertiesWrapper systemPropertiesWrapper,
AuditService auditService) {
this.asyncInstantiationBL = asyncInstantiationBL;
- this.instantiationTemplates = instantiationTemplates;
this.asyncInstantiationRepository = asyncInstantiationRepository;
this.roleProvider = roleProvider;
this.featureManager = featureManager;
@@ -95,7 +90,6 @@ public class AsyncInstantiationController extends VidRestrictedBaseController {
return asyncInstantiationRepository.listInstantiatedServicesByServiceModelId(serviceModelId);
}
}
-
@RequestMapping(value = "bulk", method = RequestMethod.POST)
public MsoResponseWrapper2<List<String>> createBulkOfServices(@RequestBody ServiceInstantiation request, HttpServletRequest httpServletRequest) {
//Push to DB according the model
@@ -174,11 +168,6 @@ public class AsyncInstantiationController extends VidRestrictedBaseController {
return new MsoResponseWrapper2(200, uuids);
}
- @GetMapping("templateTopology/{jobId}")
- public ServiceInstantiation getTemplateTopology(HttpServletRequest request, @PathVariable(value="jobId") UUID jobId) {
- return instantiationTemplates.getJobRequestAsTemplate(jobId);
- }
-
@RequestMapping(value = "/auditStatusForRetry/{trackById}", method = RequestMethod.GET)
public JobAuditStatus getResourceAuditStatus(HttpServletRequest request, @PathVariable(value="trackById") String trackById) {
return auditService.getResourceAuditStatus(trackById);
diff --git a/vid-app-common/src/main/java/org/onap/vid/controller/InstantiationTemplatesController.java b/vid-app-common/src/main/java/org/onap/vid/controller/InstantiationTemplatesController.java
new file mode 100644
index 000000000..8aae3d805
--- /dev/null
+++ b/vid-app-common/src/main/java/org/onap/vid/controller/InstantiationTemplatesController.java
@@ -0,0 +1,60 @@
+/*-
+ * ============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.controller;
+
+
+import java.util.UUID;
+import javax.servlet.http.HttpServletRequest;
+import org.onap.vid.dal.AsyncInstantiationRepository;
+import org.onap.vid.model.serviceInstantiation.ServiceInstantiation;
+import org.onap.vid.services.AsyncInstantiationBusinessLogic;
+import org.onap.vid.services.InstantiationTemplatesService;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.PathVariable;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
+
+@RestController
+@RequestMapping(InstantiationTemplatesController.INSTANTIATION_TEMPLATES)
+public class InstantiationTemplatesController extends VidRestrictedBaseController {
+
+ public static final String INSTANTIATION_TEMPLATES = "instantiationTemplates";
+
+ protected final AsyncInstantiationBusinessLogic asyncInstantiationBL;
+ protected final InstantiationTemplatesService instantiationTemplates;
+ protected final AsyncInstantiationRepository asyncInstantiationRepository;
+
+
+ @Autowired
+ public InstantiationTemplatesController(AsyncInstantiationBusinessLogic asyncInstantiationBL,
+ InstantiationTemplatesService instantiationTemplates,
+ AsyncInstantiationRepository asyncInstantiationRepository) {
+ this.asyncInstantiationBL = asyncInstantiationBL;
+ this.instantiationTemplates = instantiationTemplates;
+ this.asyncInstantiationRepository = asyncInstantiationRepository;
+ }
+
+ @GetMapping("templateTopology/{jobId}")
+ public ServiceInstantiation getTemplateTopology(HttpServletRequest request, @PathVariable(value="jobId") UUID jobId) {
+ return instantiationTemplates.getJobRequestAsTemplate(jobId);
+ }
+}
diff --git a/vid-app-common/src/main/java/org/onap/vid/model/ServiceInfo.java b/vid-app-common/src/main/java/org/onap/vid/model/ServiceInfo.java
index 85c83eb98..677d67c8e 100644
--- a/vid-app-common/src/main/java/org/onap/vid/model/ServiceInfo.java
+++ b/vid-app-common/src/main/java/org/onap/vid/model/ServiceInfo.java
@@ -24,10 +24,12 @@ package org.onap.vid.model;
import com.fasterxml.jackson.annotation.JsonProperty;
import java.io.Serializable;
import java.util.Date;
+import java.util.Map;
import java.util.Objects;
import java.util.Set;
import java.util.UUID;
import javax.persistence.Column;
+import javax.persistence.Convert;
import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
@@ -41,6 +43,8 @@ import org.hibernate.annotations.SelectBeforeUpdate;
import org.hibernate.annotations.Type;
import org.onap.portalsdk.core.domain.support.DomainVo;
import org.onap.vid.job.Job;
+import org.onap.vid.job.Job.JobStatus;
+import org.onap.vid.utils.DaoUtils.StringToLongMapAttributeConverter;
/*
The following 2 annotations let hibernate to update only fields that actually have been changed.
@@ -91,17 +95,19 @@ public class ServiceInfo extends DomainVo {
private String serviceModelVersion;
private Date createdBulkDate;
private ServiceAction action;
+ private Map<String, Long> requestSummary;
public ServiceInfo(){
}
- public ServiceInfo(String userId, Boolean aLaCarte, Job.JobStatus jobStatus, boolean pause, UUID jobId, UUID templateId,
- String owningEntityId, String owningEntityName, String project, String aicZoneId, String aicZoneName,
- String tenantId, String tenantName, String regionId, String regionName, String serviceType,
- String subscriberName, String subscriberId, String serviceInstanceId, String serviceInstanceName,
- String serviceModelId, String serviceModelName, String serviceModelVersion, Date createdBulkDate,
- ServiceAction action, boolean retryEnabled) {
+ public ServiceInfo(String userId, Boolean aLaCarte, JobStatus jobStatus, boolean pause, UUID jobId,
+ UUID templateId,
+ String owningEntityId, String owningEntityName, String project, String aicZoneId, String aicZoneName,
+ String tenantId, String tenantName, String regionId, String regionName, String serviceType,
+ String subscriberName, String subscriberId, String serviceInstanceId, String serviceInstanceName,
+ String serviceModelId, String serviceModelName, String serviceModelVersion, Date createdBulkDate,
+ ServiceAction action, boolean retryEnabled, Map<String, Long> requestSummary) {
this.userId = userId;
this.aLaCarte = aLaCarte;
this.jobStatus = jobStatus;
@@ -128,6 +134,7 @@ public class ServiceInfo extends DomainVo {
this.createdBulkDate = createdBulkDate;
this.action = action;
this.retryEnabled = retryEnabled;
+ this.requestSummary = requestSummary;
}
@Column(name = "JOB_ID", columnDefinition = "CHAR(36)")
@@ -287,6 +294,12 @@ public class ServiceInfo extends DomainVo {
return action;
}
+ @Column(name="REQUEST_SUMMARY")
+ @Convert(converter = StringToLongMapAttributeConverter.class)
+ public Map<String, Long> getRequestSummary() {
+ return requestSummary;
+ }
+
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Override
@@ -454,6 +467,10 @@ public class ServiceInfo extends DomainVo {
public void setAction(ServiceAction action) { this.action = action; }
+ public void setRequestSummary(Map<String, Long> requestSummary) {
+ this.requestSummary = requestSummary;
+ }
+
@Override
public boolean equals(Object o) {
if (this == o) return true;
@@ -488,6 +505,7 @@ public class ServiceInfo extends DomainVo {
Objects.equals(getServiceModelName(), that.getServiceModelName()) &&
Objects.equals(getServiceModelVersion(), that.getServiceModelVersion()) &&
Objects.equals(getCreatedBulkDate(), that.getCreatedBulkDate()) &&
+ Objects.equals(getRequestSummary(), that.getRequestSummary()) &&
getAction() == that.getAction();
}
@@ -497,6 +515,6 @@ public class ServiceInfo extends DomainVo {
getStatusModifiedDate(), isHidden(), isPause(), isRetryEnabled(), getDeletedAt(), getOwningEntityId(), getOwningEntityName(),
getProject(), getAicZoneId(), getAicZoneName(), getTenantId(), getTenantName(), getRegionId(), getRegionName(), getServiceType(),
getSubscriberName(), getSubscriberId(), getServiceInstanceId(), getServiceInstanceName(), getServiceModelId(), getServiceModelName(),
- getServiceModelVersion(), getCreatedBulkDate(), getAction());
+ getServiceModelVersion(), getCreatedBulkDate(), getAction(), getRequestSummary());
}
}
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 c0ee7ea4f..6729bdac8 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
@@ -20,11 +20,13 @@
package org.onap.vid.services;
+import static com.google.common.collect.Streams.concat;
import static java.util.function.Function.identity;
import static java.util.stream.Collectors.counting;
import static java.util.stream.Collectors.groupingBy;
-import static java.util.stream.Stream.concat;
+import static java.util.stream.Stream.empty;
import static org.apache.commons.lang3.ObjectUtils.defaultIfNull;
+import static org.apache.commons.lang3.StringUtils.isNotEmpty;
import static org.onap.vid.controller.MsoController.SVC_INSTANCE_ID;
import static org.onap.vid.controller.MsoController.VNF_INSTANCE_ID;
import static org.onap.vid.utils.KotlinUtilsKt.JACKSON_OBJECT_MAPPER;
@@ -41,7 +43,6 @@ import java.util.Objects;
import java.util.UUID;
import java.util.function.Consumer;
import java.util.stream.Stream;
-import org.apache.commons.lang3.StringUtils;
import org.hibernate.SessionFactory;
import org.onap.portalsdk.core.logging.logic.EELFLoggerDelegate;
import org.onap.vid.aai.AaiClientInterface;
@@ -63,6 +64,7 @@ import org.onap.vid.model.ResourceInfo;
import org.onap.vid.model.ServiceInfo;
import org.onap.vid.model.serviceInstantiation.BaseResource;
import org.onap.vid.model.serviceInstantiation.ServiceInstantiation;
+import org.onap.vid.model.serviceInstantiation.VfModule;
import org.onap.vid.mso.MsoBusinessLogicImpl;
import org.onap.vid.mso.MsoProperties;
import org.onap.vid.mso.MsoUtil;
@@ -188,9 +190,8 @@ public class AsyncInstantiationBusinessLogicImpl implements
public Map<String, Long> getSummarizedChildrenMap(ServiceInstantiation serviceInstantiation){
Stream<String> existingTypesStream =
allDeepChildResources(serviceInstantiation)
- .map(BaseResource::getModelInfo)
- .filter(Objects::nonNull)
- .map(ModelInfo::getModelType);
+ .map(this::getModelTypes)
+ .flatMap(identity());
Map<String, Long> existingTypesCounters =
existingTypesStream.collect(groupingBy(identity(), counting()));
@@ -198,6 +199,28 @@ public class AsyncInstantiationBusinessLogicImpl implements
return existingTypesCounters;
}
+ private Stream<String> getModelTypes(BaseResource resource) {
+ return concat(
+ Stream.of(resource)
+ .map(BaseResource::getModelInfo)
+ .filter(Objects::nonNull)
+ .map(ModelInfo::getModelType),
+ streamVolumeGroups(resource)
+ );
+ }
+
+ private Stream<String> streamVolumeGroups(BaseResource resource) {
+ return hasVolumeGroup(resource)
+ ? Stream.of("volumeGroup")
+ : empty();
+ }
+
+ private boolean hasVolumeGroup(BaseResource resource) {
+ return
+ resource instanceof VfModule
+ && isNotEmpty(((VfModule) resource).getVolumeGroupInstanceName());
+ }
+
private Stream<BaseResource> allDeepChildResources(BaseResource resource) {
return resource
.getChildren()
@@ -216,7 +239,7 @@ public class AsyncInstantiationBusinessLogicImpl implements
private String getOptimisticUniqueServiceInstanceName(String instanceName) {
- return StringUtils.isNotEmpty(instanceName) ? getUniqueNameFromDbOnly(instanceName) : instanceName;
+ return isNotEmpty(instanceName) ? getUniqueNameFromDbOnly(instanceName) : instanceName;
}
protected ServiceInfo createServiceInfo(String userId, ServiceInstantiation serviceInstantiation, UUID jobId, UUID templateId, Date createdBulkDate, String optimisticUniqueServiceInstanceName, ServiceInfo.ServiceAction serviceAction) {
@@ -243,7 +266,8 @@ public class AsyncInstantiationBusinessLogicImpl implements
serviceInstantiation.getModelInfo().getModelVersion(),
createdBulkDate,
serviceAction,
- false);
+ false,
+ null);
}
@Override
diff --git a/vid-app-common/src/main/java/org/onap/vid/utils/DaoUtils.java b/vid-app-common/src/main/java/org/onap/vid/utils/DaoUtils.java
index 7d3b926ea..7fb03aea8 100644
--- a/vid-app-common/src/main/java/org/onap/vid/utils/DaoUtils.java
+++ b/vid-app-common/src/main/java/org/onap/vid/utils/DaoUtils.java
@@ -20,14 +20,21 @@
package org.onap.vid.utils;
+import static java.util.Objects.isNull;
+import static org.onap.vid.utils.KotlinUtilsKt.JACKSON_OBJECT_MAPPER;
+
+import com.fasterxml.jackson.core.JsonProcessingException;
+import com.fasterxml.jackson.core.type.TypeReference;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.function.Function;
+import javax.persistence.AttributeConverter;
+import org.apache.commons.lang3.exception.ExceptionUtils;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.Transaction;
-import org.onap.vid.exceptions.GenericUncheckedException;
import org.onap.portalsdk.core.domain.FusionObject;
-
-import java.util.HashMap;
-import java.util.function.Function;
+import org.onap.vid.exceptions.GenericUncheckedException;
public class DaoUtils {
@@ -70,4 +77,40 @@ public class DaoUtils {
props.put(FusionObject.Parameters.PARAM_USERID, 0);
return props;
}
+
+ public static class StringToLongMapAttributeConverter extends JsonAttributeConverter<Map<String, Long>> {
+
+ private final TypeReference<Map<String, Long>> typeReference =
+ new TypeReference<Map<String, Long>>() {};
+
+ @Override
+ public TypeReference<Map<String, Long>> getTypeReference() {
+ return typeReference;
+ }
+ }
+
+ private static abstract class JsonAttributeConverter<T> implements AttributeConverter<T, String> {
+
+ abstract public TypeReference<T> getTypeReference();
+
+ @Override
+ public String convertToDatabaseColumn(T attribute) {
+ try {
+ return isNull(attribute) ? null
+ : JACKSON_OBJECT_MAPPER.writeValueAsString(attribute);
+ } catch (JsonProcessingException e) {
+ return ExceptionUtils.rethrow(e);
+ }
+ }
+
+ @Override
+ public T convertToEntityAttribute(String dbData) {
+ try {
+ return isNull(dbData) ? null
+ : JACKSON_OBJECT_MAPPER.readValue(dbData, getTypeReference());
+ } catch (JsonProcessingException e) {
+ return ExceptionUtils.rethrow(e);
+ }
+ }
+ }
}