use of org.onap.aaiclient.client.aai.entities.AAIResultWrapper in project so by onap.
the class AppcRunTasksTest method getVserversForAppcTest.
@Test
public void getVserversForAppcTest() throws Exception {
GenericVnf genericVnf = getTestGenericVnf();
final String aaiVnfJson = new String(Files.readAllBytes(Paths.get(JSON_FILE_LOCATION + "aaiGenericVnfWithVservers.json")));
final String aaiVserverJson = new String(Files.readAllBytes(Paths.get(JSON_FILE_LOCATION + "aaiVserverQueryResponse.json")));
AAIResultWrapper aaiResultWrapper = new AAIResultWrapper(aaiVnfJson);
ObjectMapper mapper = new ObjectMapper();
Vserver vserver = mapper.readValue(aaiVserverJson, Vserver.class);
doReturn(aaiResultWrapper).when(aaiVnfResources).queryVnfWrapperById(genericVnf);
doReturn(Optional.of(vserver)).when(aaiVnfResources).getVserver(any(AAIResourceUri.class));
appcRunTasks.getVserversForAppc(execution, genericVnf);
String vserverIdList = execution.getVariable("vserverIdList");
String expectedVserverIdList = "{\"vserverIds\":\"[\\\"1b3f44e5-d96d-4aac-bd9a-310e8cfb0af5\\\",\\\"14551849-1e70-45cd-bc5d-a256d49548a2\\\",\\\"48bd7f11-408f-417c-b834-b41c1b98f7d7\\\"]\"}";
String vmIdList = execution.getVariable("vmIdList");
String expectedVmIdList = "{\"vmIds\":\"[\\\"http://VSERVER-link.com\\\",\\\"http://VSERVER-link.com\\\",\\\"http://VSERVER-link.com\\\"]\"}";
assertEquals(vserverIdList, expectedVserverIdList);
assertEquals(vmIdList, expectedVmIdList);
}
use of org.onap.aaiclient.client.aai.entities.AAIResultWrapper in project so by onap.
the class WorkflowAction method getRelatedResourcesInVfModule.
protected <T> List<T> getRelatedResourcesInVfModule(String vnfId, String vfModuleId, Class<T> resultClass, AAIObjectName name) {
List<T> vnfcs = new ArrayList<>();
AAIResourceUri uri = AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.network().genericVnf(vnfId).vfModule(vfModuleId));
AAIResultWrapper vfModuleResultsWrapper = bbInputSetupUtils.getAAIResourceDepthOne(uri);
Optional<Relationships> relationshipsOp = vfModuleResultsWrapper.getRelationships();
if (relationshipsOp.isEmpty()) {
logger.debug("No relationships were found for vfModule in AAI");
} else {
Relationships relationships = relationshipsOp.get();
List<AAIResultWrapper> vnfcResultWrappers = relationships.getByType(name);
for (AAIResultWrapper vnfcResultWrapper : vnfcResultWrappers) {
Optional<T> vnfcOp = vnfcResultWrapper.asBean(resultClass);
vnfcOp.ifPresent(vnfcs::add);
}
}
return vnfcs;
}
use of org.onap.aaiclient.client.aai.entities.AAIResultWrapper in project so by onap.
the class ServiceEBBLoader method getExistingAAIVrfConfiguration.
protected String getExistingAAIVrfConfiguration(RelatedInstance relatedVpnBinding, org.onap.aai.domain.yang.L3Network aaiLocalNetwork) throws JsonProcessingException, VrfBondingServiceException {
Optional<Relationships> relationshipsOp = new AAIResultWrapper(new AAICommonObjectMapperProvider().getMapper().writeValueAsString(aaiLocalNetwork)).getRelationships();
if (relationshipsOp.isPresent()) {
List<AAIResultWrapper> configurationsRelatedToLocalNetwork = relationshipsOp.get().getByType(AAIFluentTypeBuilder.Types.CONFIGURATION);
if (configurationsRelatedToLocalNetwork.size() > 1) {
throw new VrfBondingServiceException("Network: " + aaiLocalNetwork.getNetworkId() + " has more than 1 configuration related to it");
}
if (configurationsRelatedToLocalNetwork.size() == 1) {
AAIResultWrapper configWrapper = configurationsRelatedToLocalNetwork.get(0);
Optional<Configuration> relatedConfiguration = configWrapper.asBean(Configuration.class);
if (relatedConfiguration.isPresent() && vrfConfigurationAlreadyExists(relatedVpnBinding, relatedConfiguration.get(), configWrapper)) {
return relatedConfiguration.get().getConfigurationId();
}
}
}
return null;
}
use of org.onap.aaiclient.client.aai.entities.AAIResultWrapper in project so by onap.
the class VnfEBBLoader method findConfigurationsInsideVfModule.
private void findConfigurationsInsideVfModule(DelegateExecution execution, org.onap.aai.domain.yang.VfModule aaiVfModule, List<Resource> resourceList, Resource vfModuleResource, List<Pair<WorkflowType, String>> aaiResourceIds) {
try {
AAIResultWrapper vfModuleWrapper = new AAIResultWrapper(new AAICommonObjectMapperProvider().getMapper().writeValueAsString(aaiVfModule));
Optional<Relationships> relationshipsOp;
relationshipsOp = vfModuleWrapper.getRelationships();
if (relationshipsOp.isPresent()) {
relationshipsOp = workflowActionUtils.extractRelationshipsVnfc(relationshipsOp.get());
addConfigToResources(relationshipsOp, resourceList, vfModuleResource, aaiResourceIds);
}
} catch (Exception ex) {
logger.error("Exception in findConfigurationsInsideVfModule", ex);
buildAndThrowException(execution, "Failed to find Configuration object from the vfModule.");
}
}
use of org.onap.aaiclient.client.aai.entities.AAIResultWrapper in project so by onap.
the class CreateVnfOperationalEnvironment method execute.
public void execute(String requestId, CloudOrchestrationRequest request) throws ApiException {
try {
setRequest(request);
ObjectMapper objectMapper = new ObjectMapper();
AAIResultWrapper aaiResultWrapper = aaiHelper.getAaiOperationalEnvironment(getEcompManagingEnvironmentId());
if (aaiResultWrapper.isEmpty()) {
throw new NotFoundException(getEcompManagingEnvironmentId() + " not found in A&AI");
}
OperationalEnvironment aaiEnv = aaiResultWrapper.asBean(OperationalEnvironment.class).get();
// Find ECOMP environments in GRM
logger.debug(" Start of GRM findRunningServicesAsString");
String searchKey = getSearchKey(aaiEnv);
String tenantContext = getTenantContext().toUpperCase();
String jsonResponse = getGrmClient().findRunningServicesAsString(searchKey, 1, tenantContext);
ServiceEndPointList sel = objectMapper.readValue(jsonResponse, ServiceEndPointList.class);
if (sel.getServiceEndPointList().size() == 0) {
throw new TenantIsolationException("GRM did not find any matches for " + searchKey + " in " + tenantContext);
}
// Replicate end-point for VNF Operating environment in GRM
List<ServiceEndPointRequest> serviceEndpointRequestList = buildEndPointRequestList(sel);
int ctr = 0;
int total = serviceEndpointRequestList.size();
for (ServiceEndPointRequest requestList : serviceEndpointRequestList) {
logger.debug("Creating endpoint " + ++ctr + " of " + total + ": " + requestList.getServiceEndPoint().getName());
getGrmClient().addServiceEndPoint(requestList);
}
// Create VNF operating in A&AI
aaiHelper.createOperationalEnvironment(aaiClientObjectBuilder.buildAAIOperationalEnvironment("INACTIVE", request));
aaiHelper.createRelationship(request.getOperationalEnvironmentId(), getEcompManagingEnvironmentId());
// Update request database
requestDb.updateInfraSuccessCompletion("SUCCESSFULLY created VNF operational environment", requestId, request.getOperationalEnvironmentId());
} catch (Exception e) {
ErrorLoggerInfo errorLoggerInfo = new ErrorLoggerInfo.Builder(MessageEnum.APIH_GENERAL_EXCEPTION, ErrorCode.DataError).build();
ValidateException validateException = new ValidateException.Builder(e.getMessage(), HttpStatus.SC_INTERNAL_SERVER_ERROR, ErrorNumbers.SVC_DETAILED_SERVICE_ERROR).cause(e).errorInfo(errorLoggerInfo).build();
throw validateException;
}
}
Aggregations