use of com.emc.storageos.db.client.model.Cluster in project coprhd-controller by CoprHD.
the class ComputeSystemHelper method updateInitiatorClusterName.
public static void updateInitiatorClusterName(DbClient dbClient, URI clusterURI, URI hostURI) {
Cluster cluster = null;
if (!NullColumnValueGetter.isNullURI(clusterURI)) {
cluster = dbClient.queryObject(Cluster.class, clusterURI);
}
List<Initiator> initiators = ComputeSystemHelper.queryInitiators(dbClient, hostURI);
for (Initiator initiator : initiators) {
initiator.setClusterName(cluster != null ? cluster.getLabel() : "");
}
dbClient.updateObject(initiators);
}
use of com.emc.storageos.db.client.model.Cluster in project coprhd-controller by CoprHD.
the class ProcessHostChangesCompleter method complete.
@Override
protected void complete(DbClient dbClient, Status status, ServiceCoded coded) throws DeviceControllerException {
if (isNotifyWorkflow()) {
// If there is a workflow, update the step to complete.
updateWorkflowStatus(status, coded);
}
// if export updates were successful, remove all old initiators and deleted hosts
if (status.equals(Status.ready)) {
for (HostStateChange hostChange : changes) {
for (URI initiatorId : hostChange.getOldInitiators()) {
Initiator initiator = dbClient.queryObject(Initiator.class, initiatorId);
dbClient.markForDeletion(initiator);
_logger.info("Initiator marked for deletion: " + this.getId());
}
}
for (URI hostId : deletedHosts) {
Host host = dbClient.queryObject(Host.class, hostId);
// don't delete host if it was provisioned by Vipr
if (!NullColumnValueGetter.isNullURI(host.getComputeElement())) {
_logger.info("do not delete provisioned host {} - disassociate it from vcenter", host.getLabel());
host.setVcenterDataCenter(NullColumnValueGetter.getNullURI());
dbClient.persistObject(host);
} else if (!NullColumnValueGetter.isNullURI(host.getBootVolumeId())) {
_logger.info("do not delete host with boot volume {} - disassociate it from vcenter", host.getLabel());
host.setVcenterDataCenter(NullColumnValueGetter.getNullURI());
dbClient.persistObject(host);
} else {
ComputeSystemHelper.doDeactivateHost(dbClient, host);
_logger.info("Deactivating Host: " + host.getId());
}
}
for (URI clusterId : deletedClusters) {
Cluster cluster = dbClient.queryObject(Cluster.class, clusterId);
List<URI> clusterHosts = ComputeSystemHelper.getChildrenUris(dbClient, clusterId, Host.class, "cluster");
// don't delete cluster if auto-exports are disabled or all hosts weren't deleted (ex: hosts provisioned by ViPR)
if (!clusterHosts.isEmpty()) {
_logger.info("do not delete cluster {} - it still has hosts - disassociate it from vcenter", cluster.getLabel());
cluster.setVcenterDataCenter(NullColumnValueGetter.getNullURI());
cluster.setExternalId(NullColumnValueGetter.getNullStr());
dbClient.persistObject(cluster);
} else {
ComputeSystemHelper.doDeactivateCluster(dbClient, cluster);
_logger.info("Deactivating Cluster: " + cluster.getId());
}
}
}
}
use of com.emc.storageos.db.client.model.Cluster in project coprhd-controller by CoprHD.
the class AbstractHostDiscoveryAdapter method setInitiator.
/**
* Sets the host/cluster values for the initiator.
*
* @param initiator
* the initiator.
* @param host
* the host.
*/
protected void setInitiator(Initiator initiator, Host host) {
initiator.setHost(host.getId());
initiator.setHostName(host.getHostName());
Cluster cluster = getCluster(host);
initiator.setClusterName(cluster != null ? cluster.getLabel() : "");
}
use of com.emc.storageos.db.client.model.Cluster in project coprhd-controller by CoprHD.
the class UnManagedVolumeService method ingestExportedVolumes.
/**
* Ingest Exported Volumes
*
* For each UnManaged Volume Find the list of masking views this volume
* is exposed to.
*
* If only 1 masking view verify if all the initiators are available on
* the existing MV. Verify the storage Ports are available in given
* VArray Verify if this export mask is available already If not, then
* create a new Export Mask with the storage Ports, initiators from
* ViPr. Else, add volume to export mask.
*
* If more than 1 masking view verify if all the initiators are
* available on all existing MVs. Verify the storage Ports within each
* Masking view are available in given VArray. Verify if this export
* mask is available already If not, then create a new Export Mask with
* the storage Ports, initiators from ViPr. Else, add volume to export
* mask.
*
* @param exportIngestParam
* @brief Add volumes to new or existing export masks; create masks when needed
* @return TaskList
* @throws InternalException
*/
@POST
@Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Path("/ingest-exported")
@CheckPermission(roles = { Role.SYSTEM_ADMIN, Role.RESTRICTED_SYSTEM_ADMIN })
public TaskList ingestExportedVolumes(VolumeExportIngestParam exportIngestParam) throws InternalException {
TaskList taskList = new TaskList();
Map<String, TaskResourceRep> taskMap = new HashMap<String, TaskResourceRep>();
BaseIngestionRequestContext requestContext = null;
try {
if (exportIngestParam.getUnManagedVolumes().size() > getMaxBulkSize()) {
throw APIException.badRequests.exceedingLimit("unmanaged volumes", getMaxBulkSize());
}
Project project = _permissionsHelper.getObjectById(exportIngestParam.getProject(), Project.class);
ArgValidator.checkEntity(project, exportIngestParam.getProject(), false);
VirtualArray varray = VolumeIngestionUtil.getVirtualArrayForVolumeCreateRequest(project, exportIngestParam.getVarray(), _permissionsHelper, _dbClient);
VirtualPool vpool = VolumeIngestionUtil.getVirtualPoolForVolumeCreateRequest(project, exportIngestParam.getVpool(), _permissionsHelper, _dbClient);
// allow ingestion for VPool without Virtual Arrays
if (null != vpool.getVirtualArrays() && !vpool.getVirtualArrays().isEmpty() && !vpool.getVirtualArrays().contains(exportIngestParam.getVarray().toString())) {
throw APIException.internalServerErrors.virtualPoolNotMatchingVArray(exportIngestParam.getVarray());
}
// check for Quotas
long unManagedVolumesCapacity = VolumeIngestionUtil.getTotalUnManagedVolumeCapacity(_dbClient, exportIngestParam.getUnManagedVolumes());
_logger.info("UnManagedVolume provisioning quota validation successful");
TenantOrg tenant = _dbClient.queryObject(TenantOrg.class, project.getTenantOrg().getURI());
CapacityUtils.validateQuotasForProvisioning(_dbClient, vpool, project, tenant, unManagedVolumesCapacity, "volume");
VolumeIngestionUtil.checkIngestionRequestValidForUnManagedVolumes(exportIngestParam.getUnManagedVolumes(), vpool, _dbClient);
requestContext = new BaseIngestionRequestContext(_dbClient, exportIngestParam.getUnManagedVolumes(), vpool, varray, project, tenant, exportIngestParam.getVplexIngestionMethod());
while (requestContext.hasNext()) {
UnManagedVolume unManagedVolume = requestContext.next();
if (null == unManagedVolume) {
_logger.warn("No Unmanaged Volume with URI {} found in database. Continuing...", requestContext.getCurrentUnManagedVolumeUri());
continue;
}
String taskId = UUID.randomUUID().toString();
Operation operation = _dbClient.createTaskOpStatus(UnManagedVolume.class, requestContext.getCurrentUnManagedVolumeUri(), taskId, ResourceOperationTypeEnum.INGEST_EXPORTED_BLOCK_OBJECTS);
TaskResourceRep task = toTask(unManagedVolume, taskId, operation);
taskMap.put(unManagedVolume.getId().toString(), task);
}
taskList.getTaskList().addAll(taskMap.values());
// find or create ExportGroup for this set of volumes being ingested
URI exportGroupResourceUri = null;
String resourceType = ExportGroupType.Host.name();
String computeResourcelabel = null;
if (null != exportIngestParam.getCluster()) {
resourceType = ExportGroupType.Cluster.name();
Cluster cluster = _dbClient.queryObject(Cluster.class, exportIngestParam.getCluster());
exportGroupResourceUri = cluster.getId();
computeResourcelabel = cluster.getLabel();
requestContext.setCluster(exportIngestParam.getCluster());
} else {
Host host = _dbClient.queryObject(Host.class, exportIngestParam.getHost());
exportGroupResourceUri = host.getId();
computeResourcelabel = host.getHostName();
requestContext.setHost(exportIngestParam.getHost());
}
ExportGroup exportGroup = VolumeIngestionUtil.verifyExportGroupExists(requestContext, requestContext.getProject().getId(), exportGroupResourceUri, exportIngestParam.getVarray(), resourceType, _dbClient);
if (null == exportGroup) {
_logger.info("Creating Export Group with label {}", computeResourcelabel);
ResourceAndUUIDNameGenerator nameGenerator = new ResourceAndUUIDNameGenerator();
exportGroup = VolumeIngestionUtil.initializeExportGroup(requestContext.getProject(), resourceType, exportIngestParam.getVarray(), computeResourcelabel, _dbClient, nameGenerator, requestContext.getTenant());
requestContext.setExportGroupCreated(true);
}
requestContext.setExportGroup(exportGroup);
_logger.info("ExportGroup {} created ", exportGroup.forDisplay());
IngestVolumesExportedSchedulingThread.executeApiTask(_asyncTaskService.getExecutorService(), requestContext, ingestStrategyFactory, this, _dbClient, taskMap, taskList);
} catch (InternalException e) {
_logger.error("InternalException occurred due to: {}", e);
throw e;
} catch (Exception e) {
_logger.error("Unexpected exception occurred due to: {}", e);
throw APIException.internalServerErrors.genericApisvcError(ExceptionUtils.getExceptionMessage(e), e);
}
return taskList;
}
use of com.emc.storageos.db.client.model.Cluster in project coprhd-controller by CoprHD.
the class HostService method validateHostData.
/**
* Validates the create/update host input data
*
* @param hostParam
* the input parameter
* @param host
* the host being updated in case of update operation.
* This parameter must be null for create operations.n
*/
protected void validateHostData(HostParam hostParam, URI tenanUri, Host host, Boolean validateConnection) {
Cluster cluster = null;
VcenterDataCenter dataCenter = null;
Project project = null;
Volume volume = null;
// validate the host type
if (hostParam.getType() != null) {
ArgValidator.checkFieldValueFromEnum(hostParam.getType(), "Type", Host.HostType.class);
}
// validate the project is present, active, and in the same tenant org
if (!NullColumnValueGetter.isNullURI(hostParam.getProject())) {
project = queryObject(Project.class, hostParam.getProject(), true);
if (!project.getTenantOrg().getURI().equals(tenanUri)) {
throw APIException.badRequests.resourcedoesNotBelongToHostTenantOrg("project");
}
}
if (!NullColumnValueGetter.isNullURI(hostParam.getBootVolume())) {
volume = queryObject(Volume.class, hostParam.getBootVolume(), true);
if (!volume.getTenant().getURI().equals(tenanUri)) {
throw APIException.badRequests.resourcedoesNotBelongToHostTenantOrg("boot volume");
}
}
// validate the cluster is present, active, and in the same tenant org
if (!NullColumnValueGetter.isNullURI(hostParam.getCluster())) {
cluster = queryObject(Cluster.class, hostParam.getCluster(), true);
if (!cluster.getTenant().equals(tenanUri)) {
throw APIException.badRequests.resourcedoesNotBelongToHostTenantOrg("cluster");
}
}
// validate the data center is present, active, and in the same tenant org
if (!NullColumnValueGetter.isNullURI(hostParam.getVcenterDataCenter())) {
dataCenter = queryObject(VcenterDataCenter.class, hostParam.getVcenterDataCenter(), true);
if (!dataCenter.getTenant().equals(tenanUri)) {
throw APIException.badRequests.resourcedoesNotBelongToHostTenantOrg("data center");
}
}
if (cluster != null) {
if (dataCenter != null) {
// check the cluster and data center are consistent
if (!dataCenter.getId().equals(cluster.getVcenterDataCenter())) {
throw APIException.badRequests.invalidParameterClusterNotInDataCenter(cluster.getLabel(), dataCenter.getLabel());
}
} else if (project != null) {
// check the cluster and data center are consistent
if (!project.getId().equals(cluster.getProject())) {
throw APIException.badRequests.invalidParameterClusterNotInHostProject(cluster.getLabel());
}
}
}
// check the host name is not a duplicate
if (host == null || (hostParam.getHostName() != null && !hostParam.getHostName().equals(host.getHostName()))) {
checkDuplicateAltId(Host.class, "hostName", EndpointUtility.changeCase(hostParam.getHostName()), "host");
}
// check the host label is not a duplicate
if (host == null || (hostParam.getName() != null && !hostParam.getName().equals(host.getLabel()))) {
checkDuplicateLabel(Host.class, hostParam.getName());
}
// If the host project is being changed, check for active exports
if (host != null && !areEqual(host.getProject(), hostParam.getProject())) {
if (ComputeSystemHelper.isHostInUse(_dbClient, host.getId())) {
throw APIException.badRequests.hostProjectChangeNotAllowed(host.getHostName());
}
}
// Find out if the host should be discoverable by checking input and current values
Boolean discoverable = hostParam.getDiscoverable() == null ? (host == null ? Boolean.FALSE : host.getDiscoverable()) : hostParam.getDiscoverable();
boolean vCenterManaged = host == null ? false : Host.HostType.Esx.name().equals(host.getType()) && !NullColumnValueGetter.isNullURI(host.getVcenterDataCenter());
// If discoverable, ensure username and password are set in the current host or parameters
if (!vCenterManaged && discoverable != null && discoverable) {
String username = hostParam.getUserName() == null ? (host == null ? null : host.getUsername()) : hostParam.getUserName();
String password = hostParam.getPassword() == null ? (host == null ? null : host.getPassword()) : hostParam.getPassword();
ArgValidator.checkFieldNotNull(username, "username");
ArgValidator.checkFieldNotNull(password, "password");
Host.HostType hostType = Host.HostType.valueOf(hostParam.getType() == null ? (host == null ? null : host.getType()) : hostParam.getType());
if (hostType != null && hostType == Host.HostType.Windows) {
Integer portNumber = hostParam.getPortNumber() == null ? (host == null ? null : host.getPortNumber()) : hostParam.getPortNumber();
ArgValidator.checkFieldNotNull(portNumber, "port_number");
}
}
if (validateConnection != null && validateConnection == true) {
if (!HostConnectionValidator.isHostConnectionValid(hostParam, host)) {
throw APIException.badRequests.invalidHostConnection();
}
}
}
Aggregations