use of org.onap.so.openstack.exceptions.MsoCloudSiteNotFound in project so by onap.
the class MsoTenantUtilsFactoryTest method getTenantUtils_shouldThrowException_whenNoCloudSiteFoundForGivenId.
@Test
public void getTenantUtils_shouldThrowException_whenNoCloudSiteFoundForGivenId() {
// GIVEN
String cloudSiteId = "CloudSiteId";
given(cloudConfig.getCloudSite(cloudSiteId)).willReturn(Optional.empty());
// WHEN
MsoCloudSiteNotFound msoCloudSiteNotFound = catchThrowableOfType(() -> msoTenantUtilsFactory.getTenantUtils(cloudSiteId), MsoCloudSiteNotFound.class);
// THEN
assertThat(msoCloudSiteNotFound.getMessage()).contains(cloudSiteId);
}
use of org.onap.so.openstack.exceptions.MsoCloudSiteNotFound in project so by onap.
the class CreateAAIInventory method heatbridge.
public void heatbridge(CloudInformation cloudInformation) throws HeatBridgeException, MsoCloudSiteNotFound {
CloudSite cloudSite = cloudConfig.getCloudSite(cloudInformation.getRegionId()).orElseThrow(() -> new MsoCloudSiteNotFound(cloudInformation.getRegionId()));
if (cloudSite.getOrchestrator() != null && MULTICLOUD_MODE.equalsIgnoreCase(cloudSite.getOrchestrator())) {
logger.debug("Skipping Heatbridge as CloudSite orchestrator is: " + MULTICLOUD_MODE);
return;
}
CloudIdentity cloudIdentity = cloudSite.getIdentityService();
String heatStackId = cloudInformation.getTemplateInstanceId().split("/")[1];
List<String> oobMgtNetNames = new ArrayList<>();
HeatBridgeApi heatBridgeClient = createClient(getAaiClient(), cloudSite, cloudIdentity, cloudInformation);
heatBridgeClient.authenticate();
List<Resource> stackResources = heatBridgeClient.queryNestedHeatStackResources(cloudInformation.getTemplateInstanceId());
List<Network> osNetworks = heatBridgeClient.getAllOpenstackProviderNetworks(stackResources);
heatBridgeClient.buildAddNetworksToAaiAction(cloudInformation.getVnfId(), cloudInformation.getVfModuleId(), osNetworks);
List<Server> osServers = heatBridgeClient.getAllOpenstackServers(stackResources);
heatBridgeClient.createPserversAndPinterfacesIfNotPresentInAai(stackResources);
List<Image> osImages = heatBridgeClient.extractOpenstackImagesFromServers(osServers);
List<Flavor> osFlavors = heatBridgeClient.extractOpenstackFlavorsFromServers(osServers);
logger.debug("Successfully queried heat stack{} for resources.", heatStackId);
// os images
if (osImages != null && !osImages.isEmpty()) {
heatBridgeClient.buildAddImagesToAaiAction(osImages);
logger.debug("Successfully built AAI actions to add images.");
} else {
logger.debug("No images to update to AAI.");
}
// flavors
if (osFlavors != null && !osFlavors.isEmpty()) {
heatBridgeClient.buildAddFlavorsToAaiAction(osFlavors);
logger.debug("Successfully built AAI actions to add flavors.");
} else {
logger.debug("No flavors to update to AAI.");
}
// compute resources
heatBridgeClient.buildAddVserversToAaiAction(cloudInformation.getVnfId(), cloudInformation.getVfModuleId(), osServers);
logger.debug("Successfully queried compute resources and built AAI vserver actions.");
// neutron resources
List<String> oobMgtNetIds = new ArrayList<>();
// if no network-id list is provided, however network-name list is
if (!CollectionUtils.isEmpty(oobMgtNetNames)) {
oobMgtNetIds = heatBridgeClient.extractNetworkIds(oobMgtNetNames);
}
heatBridgeClient.buildAddVserverLInterfacesToAaiAction(stackResources, oobMgtNetIds, cloudInformation.getOwner());
logger.debug("Successfully queried neutron resources and built AAI actions to add l-interfaces to vservers.");
heatBridgeClient.buildAddVolumes(stackResources);
// Update AAI
logger.debug("Current Dry Run Value: {}", env.getProperty("heatBridgeDryrun", Boolean.class, false));
heatBridgeClient.submitToAai(env.getProperty("heatBridgeDryrun", Boolean.class, false));
}
use of org.onap.so.openstack.exceptions.MsoCloudSiteNotFound in project so by onap.
the class MsoCommonUtils method getKeystoneAuthHolder.
/**
* Gets the Keystone Authorization
*
* @param cloudSite the cloud site
* @param tenantId the tenant id
* @return the Neutron client
* @throws MsoException the mso exception
*/
protected KeystoneAuthHolder getKeystoneAuthHolder(String cloudSiteId, String tenantId, String serviceName) throws MsoException {
CloudIdentity cloudIdentity = null;
try {
CloudSite cloudSite = cloudConfig.getCloudSite(cloudSiteId).orElseThrow(() -> new MsoCloudSiteNotFound(cloudSiteId));
String cloudId = cloudSite.getId();
String region = cloudSite.getRegionId();
cloudIdentity = cloudSite.getIdentityService();
MsoTenantUtils tenantUtils = tenantUtilsFactory.getTenantUtilsByServerType(cloudIdentity.getIdentityServerType());
String keystoneUrl = tenantUtils.getKeystoneUrl(cloudId, cloudIdentity);
if (ServerType.KEYSTONE.equals(cloudIdentity.getIdentityServerType())) {
Access access = getKeystone(tenantId, cloudIdentity, keystoneUrl);
try {
KeystoneAuthHolder keystoneAuthV2 = new KeystoneAuthHolder();
keystoneAuthV2.setServiceUrl(KeystoneUtils.findEndpointURL(access.getServiceCatalog(), serviceName, region, "public"));
keystoneAuthV2.setId(access.getToken().getId());
return keystoneAuthV2;
} catch (RuntimeException e) {
String error = "Openstack did not match an orchestration service for: region=" + region + ",cloud=" + cloudIdentity.getIdentityUrl();
throw new MsoAdapterException(error, e);
}
} else if (ServerType.KEYSTONE_V3.equals(cloudIdentity.getIdentityServerType())) {
try {
return keystoneV3Authentication.getToken(cloudSite, tenantId, serviceName);
} catch (ServiceEndpointNotFoundException e) {
String error = "cloud did not match an orchestration service for: region=" + region + ",cloud=" + cloudIdentity.getIdentityUrl();
throw new MsoAdapterException(error, e);
}
} else {
throw new MsoAdapterException("Unknown Keystone Server Type");
}
} catch (OpenStackResponseException e) {
if (e.getStatus() == 401) {
String error = "Authentication Failure: tenant=" + tenantId + ",cloud=" + cloudIdentity.getId();
throw new MsoAdapterException(error);
} else {
throw keystoneErrorToMsoException(e, TOKEN_AUTH);
}
} catch (OpenStackConnectException e) {
MsoIOException me = new MsoIOException(e.getMessage(), e);
me.addContext(TOKEN_AUTH);
throw me;
} catch (RuntimeException e) {
throw runtimeExceptionToMsoException(e, TOKEN_AUTH);
}
}
use of org.onap.so.openstack.exceptions.MsoCloudSiteNotFound in project so by onap.
the class MsoKeystoneUtils method deleteTenant.
/**
* Delete the specified Tenant (by ID) in the given cloud. This method returns true or false, depending on whether
* the tenant existed and was successfully deleted, or if the tenant already did not exist. Both cases are treated
* as success (no Exceptions).
* <p>
* Note for the AIC Cloud (DCP/LCP): all admin requests go to the centralized identity service in DCP. So deleting a
* tenant from one cloudSiteId will remove it from all sites managed by that identity service.
* <p>
*
* @param tenantId The Openstack ID of the tenant to delete
* @param cloudSiteId The cloud identifier from which to delete the tenant.
* @return true if the tenant was deleted, false if the tenant did not exist.
* @throws MsoOpenstackException If the Openstack API call returns an exception.
*/
public boolean deleteTenant(String tenantId, String cloudSiteId) throws MsoException {
// Obtain the cloud site information where we will query the tenant
CloudSite cloudSite = cloudConfig.getCloudSite(cloudSiteId).orElseThrow(() -> new MsoCloudSiteNotFound(cloudSiteId));
Keystone keystoneAdminClient = getKeystoneAdminClient(cloudSite);
try {
// Check that the tenant exists. Also, need the ID to delete
Tenant tenant = findTenantById(keystoneAdminClient, tenantId);
if (tenant == null) {
LOGGER.error("{} Tenant id {} not found on cloud site id {}, {}", MessageEnum.RA_TENANT_NOT_FOUND, tenantId, cloudSiteId, ErrorCode.DataError.getValue());
return false;
}
OpenStackRequest<Void> request = keystoneAdminClient.tenants().delete(tenant.getId());
executeAndRecordOpenstackRequest(request);
LOGGER.debug("Deleted Tenant {} ({})", tenant.getId(), tenant.getName());
} catch (OpenStackBaseException e) {
// Convert Keystone OpenStackResponseException to MsoOpenstackException
throw keystoneErrorToMsoException(e, DELETE_TENANT);
} catch (RuntimeException e) {
// Catch-all
throw runtimeExceptionToMsoException(e, DELETE_TENANT);
}
return true;
}
use of org.onap.so.openstack.exceptions.MsoCloudSiteNotFound in project so by onap.
the class MsoNeutronUtils method getNeutronPort.
public Optional<Port> getNeutronPort(String neutronPortId, String tenantId, String cloudSiteId) {
try {
logger.debug("Finding Neutron port:" + neutronPortId);
CloudSite cloudSite = cloudConfig.getCloudSite(cloudSiteId).orElseThrow(() -> new MsoCloudSiteNotFound(cloudSiteId));
Quantum neutronClient = getNeutronClient(cloudSite, tenantId);
Port port = findPortById(neutronClient, neutronPortId);
if (port == null) {
return Optional.empty();
}
return Optional.of(port);
} catch (RuntimeException | MsoException e) {
logger.error("Error retrieving neutron port", e);
return Optional.empty();
}
}
Aggregations