* 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.
import java.util.HashMap;
import java.util.List;
import java.util.Map;
+import java.util.Map.Entry;
import java.util.Optional;
+import java.util.Set;
+import java.util.stream.Collectors;
import javax.ws.rs.container.ContainerRequestContext;
import javax.ws.rs.core.MultivaluedMap;
import javax.ws.rs.core.Response;
}
}
- public InfraActiveRequests duplicateCheck(Actions action, HashMap<String, String> instanceIdMap,
- String instanceName, String requestScope, InfraActiveRequests currentActiveReq) throws ApiException {
+ public InfraActiveRequests duplicateCheck(Actions action, Map<String, String> instanceIdMap, String instanceName,
+ String requestScope, InfraActiveRequests currentActiveReq) throws ApiException {
InfraActiveRequests dup = null;
try {
if (!(instanceName == null && "service".equals(requestScope) && (action == Action.createInstance
String requestScope = requestScopeFromUri(requestUri);
msoRequest.createErrorRequestRecord(Status.FAILED, requestId, validateException.getMessage(), action,
- requestScope, requestJSON);
+ requestScope, requestJSON, null, null);
throw validateException;
}
}
- public void parseRequest(ServiceInstancesRequest sir, HashMap<String, String> instanceIdMap, Actions action,
+ public void parseRequest(ServiceInstancesRequest sir, Map<String, String> instanceIdMap, Actions action,
String version, String requestJSON, Boolean aLaCarte, String requestId,
InfraActiveRequests currentActiveReq) throws ValidateException, RequestDbFailureException {
int reqVersion = Integer.parseInt(version.substring(1));
}
public void buildErrorOnDuplicateRecord(InfraActiveRequests currentActiveReq, Actions action,
- HashMap<String, String> instanceIdMap, String instanceName, String requestScope, InfraActiveRequests dup)
+ Map<String, String> instanceIdMap, String instanceName, String requestScope, InfraActiveRequests dup)
throws ApiException {
String instance = null;
if (StringUtils.isNotBlank(instanceId)) {
if (ModelType.service.name().equalsIgnoreCase(requestScope)) {
currentActiveReq.setServiceInstanceId(instanceId);
- } else if (ModelType.vnf.name().equalsIgnoreCase(requestScope)) {
+ } else if (ModelType.vnf.name().equalsIgnoreCase(requestScope)
+ || ModelType.cnf.name().equalsIgnoreCase(requestScope)) {
currentActiveReq.setVnfId(instanceId);
} else if (ModelType.vfModule.name().equalsIgnoreCase(requestScope)) {
currentActiveReq.setVfModuleId(instanceId);
}
protected String setServiceInstanceId(String requestScope, ServiceInstancesRequest sir) {
+ String serviceInstanceId = null;
if (sir.getServiceInstanceId() != null) {
- return sir.getServiceInstanceId();
- } else if (requestScope.equalsIgnoreCase(ModelType.instanceGroup.toString())) {
- RelatedInstanceList[] relatedInstances = sir.getRequestDetails().getRelatedInstanceList();
- if (relatedInstances != null) {
- for (RelatedInstanceList relatedInstanceList : relatedInstances) {
- RelatedInstance relatedInstance = relatedInstanceList.getRelatedInstance();
- if (relatedInstance.getModelInfo().getModelType() == ModelType.service) {
- return relatedInstance.getInstanceId();
- }
- }
+ serviceInstanceId = sir.getServiceInstanceId();
+ } else {
+ Optional<String> serviceInstanceIdForInstance = getServiceInstanceIdForInstanceGroup(requestScope, sir);
+ if (serviceInstanceIdForInstance.isPresent()) {
+ serviceInstanceId = serviceInstanceIdForInstance.get();
}
}
- return null;
+ return serviceInstanceId;
}
private String requestScopeFromUri(String requestUri) {
requestScope = ModelType.vnf.name();
} else if (requestUri.contains(ModelType.pnf.name())) {
requestScope = ModelType.pnf.name();
+
+ } else if (requestUri.contains(ModelType.cnf.name())) {
+ requestScope = ModelType.cnf.name();
} else {
requestScope = ModelType.service.name();
}
throw validateException;
}
+ }
+
+ else if (modelInfo.getModelType().equals(ModelType.pnf)) {
+ recipeLookupResult = new RecipeLookupResult("/mso/async/services/WorkflowActionBB", 180);
} else if (modelInfo.getModelType().equals(ModelType.instanceGroup)) {
recipeLookupResult = new RecipeLookupResult("/mso/async/services/WorkflowActionBB", 180);
+ } else if (modelInfo.getModelType().equals(ModelType.cnf)) {
+ recipeLookupResult = new RecipeLookupResult("/mso/async/services/WorkflowActionBB", 180);
}
if (recipeLookupResult == null) {
if (params.containsKey("service")) {
Service service = serviceMapper(params);
- addUserParams(userParams, service.getInstanceParams());
+ // Filter out non-string params for backward compatibility
+ Map<String, String> svcStrParams = service.getInstanceParams().stream().map(Map::entrySet)
+ .flatMap(Set::stream).filter(e -> e.getValue() instanceof String)
+ .collect(Collectors.toMap(Entry::getKey, e -> (String) e.getValue()));
+ userParams.putAll(svcStrParams);
for (Networks network : service.getResources().getNetworks()) {
addUserParams(userParams, network.getInstanceParams());
return null;
}
+ protected Optional<String> getServiceInstanceIdForValidationError(ServiceInstancesRequest sir,
+ HashMap<String, String> instanceIdMap, String requestScope) {
+ if (instanceIdMap != null && !instanceIdMap.isEmpty() && instanceIdMap.get("serviceInstanceId") != null) {
+ return Optional.of(instanceIdMap.get("serviceInstanceId"));
+ } else {
+ return getServiceInstanceIdForInstanceGroup(requestScope, sir);
+ }
+ }
+
+ protected Optional<String> getServiceInstanceIdForInstanceGroup(String requestScope, ServiceInstancesRequest sir) {
+ if (requestScope.equalsIgnoreCase(ModelType.instanceGroup.toString())) {
+ RelatedInstanceList[] relatedInstances = sir.getRequestDetails().getRelatedInstanceList();
+ if (relatedInstances != null) {
+ for (RelatedInstanceList relatedInstanceList : relatedInstances) {
+ RelatedInstance relatedInstance = relatedInstanceList.getRelatedInstance();
+ if (relatedInstance.getModelInfo().getModelType() == ModelType.service) {
+ return Optional.ofNullable(relatedInstance.getInstanceId());
+ }
+ }
+ }
+ }
+ return Optional.empty();
+ }
+
private RecipeLookupResult getDefaultVnfUri(ServiceInstancesRequest sir, Actions action) {
String defaultSource = getDefaultModel(sir);
VnfRecipe vnfRecipe = catalogDbClient.getFirstVnfRecipeByNfRoleAndAction(defaultSource, action.toString());
throw new ValidationException("vfModuleCustomization");
} else if (vfModule == null && vfmc != null) {
vfModule = vfmc.getVfModule(); // can't be null as vfModuleModelUUID is not-null property in
- // VfModuleCustomization table
+ // VfModuleCustomization table
}
if (modelInfo.getModelVersionId() == null) {