use of org.onap.so.db.request.beans.InfraActiveRequests in project so by onap.
the class RequestsDbClient method updateInfraActiveRequests.
/**
* Required for groovy usage. Cannot use Spring Autowired variables
*
* @param request
* @param basicAuth
* @param host
*/
public void updateInfraActiveRequests(InfraActiveRequests request, String basicAuth, String host) {
RestTemplate template = new RestTemplate();
template.getInterceptors().add(new SOSpringClientFilter());
template.getInterceptors().add(new SpringClientPayloadFilter());
HttpHeaders headers = new HttpHeaders();
headers.set(HttpHeaders.AUTHORIZATION, basicAuth);
headers.set(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON);
headers.set(HttpHeaders.ACCEPT, MediaType.APPLICATION_JSON);
URI uri = getUri(host + "/infraActiveRequests/" + request.getRequestId());
HttpEntity<InfraActiveRequests> entity = new HttpEntity<>(request, headers);
template.put(uri, entity);
}
use of org.onap.so.db.request.beans.InfraActiveRequests in project so by onap.
the class RequestsDBHelper method updateInfraSuccessCompletion.
/**
* This util method is to update the InfraRequest table to Complete
*
* @param msg - string, unique message for each caller
* @param requestId - string
* @param operationalEnvironmentId - string
* @return void - nothing
* @throws Exception
*/
public void updateInfraSuccessCompletion(String msg, String requestId, String operationalEnvironmentId) {
methodName = "updateInfraSuccessCompletion() method.";
classMethodMessage = className + " " + methodName;
logger.debug("Begin of {}", classMethodMessage);
InfraActiveRequests request = requestsDbClient.getInfraActiveRequestbyRequestId(requestId);
request.setRequestStatus("COMPLETE");
request.setStatusMessage("SUCCESSFUL, operationalEnvironmentId - " + operationalEnvironmentId + "; Success Message: " + msg);
request.setProgress(100L);
request.setLastModifiedBy("APIH");
request.setOperationalEnvId(operationalEnvironmentId);
if (request.getRequestScope() == null) {
request.setRequestScope(UNKNOWN);
}
Timestamp endTimeStamp = new Timestamp(System.currentTimeMillis());
request.setEndTime(endTimeStamp);
requestsDbClient.save(request);
logger.debug("End of {}", classMethodMessage);
}
use of org.onap.so.db.request.beans.InfraActiveRequests in project so by onap.
the class RequestDbClientTest method updateInfraActiveRequestsTest.
@Test
public void updateInfraActiveRequestsTest() {
InfraActiveRequests request = new InfraActiveRequests();
request.setRequestId("1");
URI uri = URI.create("/infraActiveRequests/1");
requestsDbClient.patchInfraActiveRequests(request);
Mockito.verify(restTemplate, times(1)).exchange(eq(uri), eq(HttpMethod.PATCH), isA(HttpEntity.class), eq(String.class));
}
use of org.onap.so.db.request.beans.InfraActiveRequests in project so by onap.
the class RequestsDBHelperTest method updateInfraFailureCompletion.
@Test
public void updateInfraFailureCompletion() {
when(requestsDbClient.getInfraActiveRequestbyRequestId(any())).thenReturn(new InfraActiveRequests());
requestsDBHelper.updateInfraFailureCompletion("messageText", "requestId", "operationalEnvId");
ArgumentCaptor<InfraActiveRequests> infraActiveRequests = ArgumentCaptor.forClass(InfraActiveRequests.class);
verify(requestsDbClient, times(1)).save(infraActiveRequests.capture());
assertEquals("FAILED", infraActiveRequests.getValue().getRequestStatus());
assertEquals("APIH", infraActiveRequests.getValue().getLastModifiedBy());
assertEquals(Long.valueOf(100), infraActiveRequests.getValue().getProgress());
assertEquals("FAILURE, operationalEnvironmentId - operationalEnvId; Error message: messageText", infraActiveRequests.getValue().getStatusMessage());
assertEquals("operationalEnvId", infraActiveRequests.getValue().getOperationalEnvId());
}
use of org.onap.so.db.request.beans.InfraActiveRequests in project so by onap.
the class BBInputSetup method getGBBMacroUserParams.
protected GeneralBuildingBlock getGBBMacroUserParams(ExecuteBuildingBlock executeBB, RequestDetails requestDetails, Map<ResourceKey, String> lookupKeyMap, String vnfType, String bbName, String key, GeneralBuildingBlock gBB, RequestParameters requestParams, Service service, String input) throws Exception {
ServiceInstance serviceInstance = gBB.getServiceInstance();
org.onap.so.serviceinstancebeans.Service serviceMacro = mapper.readValue(input, org.onap.so.serviceinstancebeans.Service.class);
Resources resources = serviceMacro.getResources();
Vnfs vnfs = null;
VfModules vfModules = null;
Networks networks = null;
CloudConfiguration cloudConfiguration = requestDetails.getCloudConfiguration();
CloudRegion cloudRegion = setCloudConfiguration(gBB, cloudConfiguration);
BBInputSetupParameter parameter = new BBInputSetupParameter.Builder().setRequestId(executeBB.getRequestId()).setService(service).setBbName(bbName).setServiceInstance(serviceInstance).setLookupKeyMap(lookupKeyMap).build();
if (bbName.contains(VNF) || (bbName.contains(CONTROLLER) && (VNF).equalsIgnoreCase(executeBB.getBuildingBlock().getBpmnScope()))) {
String vnfInstanceName = lookupKeyMap.get(ResourceKey.VNF_INSTANCE_NAME);
if (StringUtils.isNotBlank(vnfInstanceName)) {
vnfs = findVnfsByInstanceName(vnfInstanceName, resources);
} else {
vnfs = findVnfsByKey(key, resources);
}
// Vnf level cloud configuration takes precedence over service level cloud configuration.
if (vnfs.getCloudConfiguration() != null) {
setCloudConfiguration(gBB, vnfs.getCloudConfiguration());
}
String vnfId = lookupKeyMap.get(ResourceKey.GENERIC_VNF_ID);
// This stores the vnf id in request db to be retrieved later when
// working on a vf module or volume group
InfraActiveRequests request = this.bbInputSetupUtils.getInfraActiveRequest(executeBB.getRequestId());
if (request != null) {
this.bbInputSetupUtils.updateInfraActiveRequestVnfId(request, vnfId);
}
parameter.setModelInfo(vnfs.getModelInfo());
parameter.setInstanceName(vnfs.getInstanceName());
parameter.setPlatform(vnfs.getPlatform());
parameter.setLineOfBusiness(vnfs.getLineOfBusiness());
parameter.setResourceId(vnfId);
parameter.setVnfType(vnfType);
parameter.setInstanceParams(vnfs.getInstanceParams());
parameter.setProductFamilyId(requestDetails.getRequestInfo().getProductFamilyId());
String applicationId = "";
if (vnfs.getApplicationId() != null) {
applicationId = vnfs.getApplicationId();
}
parameter.setApplicationId(applicationId);
this.populateGenericVnf(parameter);
} else if (bbName.contains(PNF) || (bbName.contains(CONTROLLER) && (PNF).equalsIgnoreCase(executeBB.getBuildingBlock().getBpmnScope()))) {
String pnfId = lookupKeyMap.get(ResourceKey.PNF);
resources.getPnfs().stream().filter(pnfs -> Objects.equals(key, pnfs.getModelInfo().getModelCustomizationId())).findFirst().ifPresent(pnfs -> BBInputSetupPnf.populatePnfToServiceInstance(pnfs, pnfId, serviceInstance));
} else if (bbName.contains(VF_MODULE) || bbName.contains(VOLUME_GROUP) || (bbName.contains(CONTROLLER) && (VF_MODULE).equalsIgnoreCase(executeBB.getBuildingBlock().getBpmnScope()))) {
String vfModuleInstanceName = lookupKeyMap.get(ResourceKey.VF_MODULE_INSTANCE_NAME);
if (StringUtils.isNotBlank(vfModuleInstanceName)) {
vfModules = getVfModulesByInstanceName(vfModuleInstanceName, resources);
} else {
vfModules = getVfModulesByKey(key, resources);
}
String vfModulesName = vfModules.getInstanceName();
String vfModulesModelCustId = vfModules.getModelInfo().getModelCustomizationId();
// Get the Vnf associated with vfModule
Optional<org.onap.so.serviceinstancebeans.Vnfs> parentVnf = resources.getVnfs().stream().filter(aVnf -> aVnf.getCloudConfiguration() != null).filter(aVnf -> aVnf.getVfModules().stream().anyMatch(aVfModules -> aVfModules.getInstanceName().equals(vfModulesName) && aVfModules.getModelInfo().getModelCustomizationId().equals(vfModulesModelCustId))).findAny();
// Get the cloud configuration from this Vnf
if (parentVnf.isPresent()) {
cloudRegion = setCloudConfiguration(gBB, parentVnf.get().getCloudConfiguration());
}
lookupKeyMap.put(ResourceKey.GENERIC_VNF_ID, getVnfId(executeBB, lookupKeyMap));
parameter.setModelInfo(vfModules.getModelInfo());
if (bbName.contains(VOLUME_GROUP)) {
parameter.setResourceId(lookupKeyMap.get(ResourceKey.VOLUME_GROUP_ID));
parameter.setInstanceName(vfModules.getVolumeGroupInstanceName());
parameter.setVnfType(vnfType);
parameter.setInstanceParams(vfModules.getInstanceParams());
ServiceModel serviceModel = new ServiceModel();
serviceModel.setCurrentService(service);
parameter.setServiceModel(serviceModel);
this.populateVolumeGroup(parameter);
} else {
parameter.setResourceId(lookupKeyMap.get(ResourceKey.VF_MODULE_ID));
CloudConfiguration cloudConfig = new CloudConfiguration();
cloudConfig.setLcpCloudRegionId(cloudRegion.getLcpCloudRegionId());
cloudConfig.setCloudOwner(cloudRegion.getCloudOwner());
ServiceModel serviceModel = new ServiceModel();
serviceModel.setCurrentService(service);
parameter.setServiceModel(serviceModel);
parameter.setCloudConfiguration(cloudConfig);
parameter.setInstanceName(vfModules.getInstanceName());
parameter.setInstanceParams(vfModules.getInstanceParams());
this.populateVfModule(parameter);
gBB.getRequestContext().setIsHelm(parameter.getIsHelm());
}
} else if (bbName.contains(NETWORK)) {
networks = findNetworksByKey(key, resources);
String networkId = lookupKeyMap.get(ResourceKey.NETWORK_ID);
if (networks != null) {
// If service level cloud configuration is not provided then get it from networks.
if (cloudConfiguration == null) {
Optional<org.onap.so.serviceinstancebeans.Networks> netWithCloudConfig = resources.getNetworks().stream().filter(aNetwork -> aNetwork.getCloudConfiguration() != null).findAny();
if (netWithCloudConfig.isPresent()) {
setCloudConfiguration(gBB, netWithCloudConfig.get().getCloudConfiguration());
} else {
logger.debug("Could not find any cloud configuration for this request.");
}
}
parameter.setInstanceName(networks.getInstanceName());
parameter.setModelInfo(networks.getModelInfo());
parameter.setInstanceParams(networks.getInstanceParams());
parameter.setResourceId(networkId);
this.populateL3Network(parameter);
}
} else if (bbName.contains("Configuration")) {
String configurationId = lookupKeyMap.get(ResourceKey.CONFIGURATION_ID);
ModelInfo configurationModelInfo = new ModelInfo();
configurationModelInfo.setModelCustomizationUuid(key);
ConfigurationResourceCustomization configurationCust = findConfigurationResourceCustomization(configurationModelInfo, service);
if (configurationCust != null) {
parameter.setModelInfo(configurationModelInfo);
parameter.setResourceId(configurationId);
parameter.setConfigurationResourceKeys(executeBB.getConfigurationResourceKeys());
parameter.setRequestDetails(executeBB.getRequestDetails());
this.populateConfiguration(parameter);
} else {
logger.debug("Could not find a configuration customization with key: {}", key);
}
}
return gBB;
}
Aggregations