* ================================================================================
* Modifications Copyright (c) 2019 Samsung
* ================================================================================
+ * Modifications Copyright (c) 2020 Nokia
+ * ================================================================================
* 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
import java.util.HashMap;
import java.util.Map;
import java.util.Optional;
-import org.onap.so.cloud.authentication.AuthenticationMethodFactory;
import org.onap.so.db.catalog.beans.CloudIdentity;
import org.onap.so.db.catalog.beans.CloudSite;
import org.onap.logging.filter.base.ErrorCode;
import org.onap.so.openstack.exceptions.MsoTenantAlreadyExists;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import com.woorea.openstack.base.client.OpenStackBaseException;
import com.woorea.openstack.base.client.OpenStackConnectException;
public class MsoKeystoneUtils extends MsoTenantUtils {
public static final String DELETE_TENANT = "Delete Tenant";
- private static Logger logger = LoggerFactory.getLogger(MsoKeystoneUtils.class);
-
- @Autowired
- private AuthenticationMethodFactory authenticationMethodFactory;
-
- @Autowired
- private MsoHeatUtils msoHeatUtils;
-
- @Autowired
- private MsoNeutronUtils msoNeutronUtils;
-
- @Autowired
- private MsoTenantUtilsFactory tenantUtilsFactory;
+ private static final Logger LOGGER = LoggerFactory.getLogger(MsoKeystoneUtils.class);
/**
* Create a tenant with the specified name in the given cloud. If the tenant already exists, an Exception will be
// Obtain the cloud site information where we will create the tenant
Optional<CloudSite> cloudSiteOpt = cloudConfig.getCloudSite(cloudSiteId);
if (!cloudSiteOpt.isPresent()) {
- logger.error("{} MSOCloudSite {} not found {} ", MessageEnum.RA_CREATE_TENANT_ERR, cloudSiteId,
+ LOGGER.error("{} MSOCloudSite {} not found {} ", MessageEnum.RA_CREATE_TENANT_ERR, cloudSiteId,
ErrorCode.DataError.getValue());
throw new MsoCloudSiteNotFound(cloudSiteId);
}
if (tenant != null) {
// Tenant already exists. Throw an exception
- logger.error("{} Tenant name {} already exists on Cloud site id {}, {}",
+ LOGGER.error("{} Tenant name {} already exists on Cloud site id {}, {}",
MessageEnum.RA_TENANT_ALREADY_EXIST, tenantName, cloudSiteId, ErrorCode.DataError.getValue());
throw new MsoTenantAlreadyExists(tenantName, cloudSiteId);
}
// Failed to attach MSO User to the new tenant. Can't operate without access,
// so roll back the tenant.
if (!backout) {
- logger.warn("{} Create Tenant errored, Tenant deletion suppressed {} ",
+ LOGGER.warn("{} Create Tenant errored, Tenant deletion suppressed {} ",
MessageEnum.RA_CREATE_TENANT_ERR, ErrorCode.DataError.getValue());
} else {
try {
executeAndRecordOpenstackRequest(request);
} catch (Exception e2) {
// Just log this one. We will report the original exception.
- logger.error("{} Nested exception rolling back tenant {} ", MessageEnum.RA_CREATE_TENANT_ERR,
+ LOGGER.error("{} Nested exception rolling back tenant {} ", MessageEnum.RA_CREATE_TENANT_ERR,
ErrorCode.DataError.getValue(), e2);
}
}
// 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,
+ 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());
+ LOGGER.debug("Deleted Tenant {} ({})", tenant.getId(), tenant.getName());
} catch (OpenStackBaseException e) {
// Convert Keystone OpenStackResponseException to MsoOpenstackException
throw keystoneErrorToMsoException(e, DELETE_TENANT);
Tenant tenant = findTenantByName(keystoneAdminClient, tenantName);
if (tenant == null) {
// OK if tenant already doesn't exist.
- logger.error("{} Tenant {} not found on Cloud site id {}, {}", MessageEnum.RA_TENANT_NOT_FOUND,
+ LOGGER.error("{} Tenant {} not found on Cloud site id {}, {}", MessageEnum.RA_TENANT_NOT_FOUND,
tenantName, cloudSiteId, ErrorCode.DataError.getValue());
return false;
}
OpenStackRequest<Void> request = keystoneAdminClient.tenants().delete(tenant.getId());
executeAndRecordOpenstackRequest(request);
- logger.debug("Deleted Tenant {} ({})", tenant.getId(), tenant.getName());
+ LOGGER.debug("Deleted Tenant {} ({})", tenant.getId(), tenant.getName());
} catch (OpenStackBaseException e) {
// Note: It doesn't seem to matter if tenant doesn't exist, no exception is thrown.
} catch (RuntimeException e) {
String error = "Identity service not found: region=" + region + ",cloud=" + cloudIdentity.getId();
- logger.error("{} Region: {} Cloud identity {} {} Exception in findEndpointURL ",
+ LOGGER.error("{} Region: {} Cloud identity {} {} Exception in findEndpointURL ",
MessageEnum.IDENTITY_SERVICE_NOT_FOUND, region, cloudIdentity.getId(),
ErrorCode.DataError.getValue(), e);
throw new MsoAdapterException(error, e);
if (e.getStatus() == 404) {
return null;
} else {
- logger.error("{} {} Openstack Error, GET Tenant by Id ({}): ", MessageEnum.RA_CONNECTION_EXCEPTION,
+ LOGGER.error("{} {} Openstack Error, GET Tenant by Id ({}): ", MessageEnum.RA_CONNECTION_EXCEPTION,
ErrorCode.DataError.getValue(), tenantId, e);
throw e;
}
if (e.getStatus() == 404) {
return null;
} else {
- logger.error("{} {} Openstack Error, GET Tenant By Name ({}) ", MessageEnum.RA_CONNECTION_EXCEPTION,
+ LOGGER.error("{} {} Openstack Error, GET Tenant By Name ({}) ", MessageEnum.RA_CONNECTION_EXCEPTION,
ErrorCode.DataError.getValue(), tenantName, e);
throw e;
}
// Not found by ID. Search for name
return findUserByName(adminClient, userNameOrId);
} else {
- logger.error("{} {} Openstack Error, GET User ({}) ", MessageEnum.RA_CONNECTION_EXCEPTION,
+ LOGGER.error("{} {} Openstack Error, GET User ({}) ", MessageEnum.RA_CONNECTION_EXCEPTION,
ErrorCode.DataError.getValue(), userNameOrId, e);
throw e;
}
if (e.getStatus() == 404) {
return null;
} else {
- logger.error("{} {} Openstack Error, GET User By Name ({}): ", MessageEnum.RA_CONNECTION_EXCEPTION,
+ LOGGER.error("{} {} Openstack Error, GET User By Name ({}): ", MessageEnum.RA_CONNECTION_EXCEPTION,
ErrorCode.DataError.getValue(), userName, e);
throw e;
}