use of com.emc.storageos.db.client.model.TenantOrg in project coprhd-controller by CoprHD.
the class HDSProtectionOperations method createSecondaryVolumeForClone.
/**
* Creates secondary volume for ShadowImage pair operations.
*
* @param storageSystem
* @param sourceVolume
* @param targetVolume
* @throws Exception
*/
public void createSecondaryVolumeForClone(StorageSystem storageSystem, URI sourceVolume, Volume targetVolume) throws Exception {
log.info("SecondaryVolume creation operation started");
String taskId = UUID.randomUUID().toString();
TaskCompleter taskCompleter = new VolumeCreateCompleter(targetVolume.getId(), taskId);
String asyncTaskMessageId = null;
HDSApiClient hdsApiClient = HDSUtils.getHDSApiClient(hdsApiFactory, storageSystem);
String systemObjectID = HDSUtils.getSystemObjectID(storageSystem);
BlockObject sourceObj = BlockObject.fetch(dbClient, sourceVolume);
URI tenantUri = null;
StoragePool targetPool = dbClient.queryObject(StoragePool.class, targetVolume.getPool());
if (sourceObj instanceof BlockSnapshot) {
// In case of snapshot, get the tenant from its parent volume
NamedURI parentVolUri = ((BlockSnapshot) sourceObj).getParent();
Volume parentVolume = dbClient.queryObject(Volume.class, parentVolUri);
tenantUri = parentVolume.getTenant().getURI();
TenantOrg tenantOrg = dbClient.queryObject(TenantOrg.class, tenantUri);
// String cloneLabel = generateLabel(tenantOrg, cloneObj);
} else {
// This is a default flow
tenantUri = ((Volume) sourceObj).getTenant().getURI();
}
if (targetVolume.getThinlyProvisioned()) {
asyncTaskMessageId = hdsApiClient.createThinVolumes(systemObjectID, targetPool.getNativeId(), targetVolume.getCapacity(), 1, targetVolume.getLabel(), HDSConstants.QUICK_FORMAT_TYPE, storageSystem.getModel());
} else {
String poolObjectID = HDSUtils.getPoolObjectID(targetPool);
asyncTaskMessageId = hdsApiClient.createThickVolumes(systemObjectID, poolObjectID, targetVolume.getCapacity(), 1, targetVolume.getLabel(), null, storageSystem.getModel(), null);
}
if (asyncTaskMessageId != null) {
HDSJob createHDSJob = new HDSCreateVolumeJob(asyncTaskMessageId, targetVolume.getStorageController(), targetPool.getId(), taskCompleter);
hdsCommandHelper.waitForAsyncHDSJob(createHDSJob);
} else {
throw HDSException.exceptions.asyncTaskFailed("Unable to get async taskId from HiCommand Device Manager for the create volume call");
}
log.info("SecondaryVolume creation operation completed successfully");
}
use of com.emc.storageos.db.client.model.TenantOrg in project coprhd-controller by CoprHD.
the class HDSStorageDevice method doCreateVolumes.
/*
* (non-Javadoc)
*
* @see com.emc.storageos.volumecontroller.BlockStorageDevice#doCreateVolumes(com.emc.storageos.db.client.model.StorageSystem,
* com.emc.storageos.db.client.model.StoragePool, java.lang.String, java.util.List,
* com.emc.storageos.volumecontroller.impl.utils.VirtualPoolCapabilityValuesWrapper, com.emc.storageos.volumecontroller.TaskCompleter)
*/
@Override
public void doCreateVolumes(StorageSystem storageSystem, StoragePool storagePool, String opId, List<Volume> volumes, VirtualPoolCapabilityValuesWrapper capabilities, TaskCompleter taskCompleter) throws DeviceControllerException {
String label = null;
Long capacity = null;
boolean isThinVolume = false;
boolean opCreationFailed = false;
StringBuilder logMsgBuilder = new StringBuilder(String.format("Create Volume Start - Array:%s, Pool:%s", storageSystem.getSerialNumber(), storagePool.getNativeGuid()));
for (Volume volume : volumes) {
logMsgBuilder.append(String.format("%nVolume:%s , IsThinlyProvisioned: %s", volume.getLabel(), volume.getThinlyProvisioned()));
if ((label == null) && (volumes.size() == 1)) {
String tenantName = "";
try {
TenantOrg tenant = dbClient.queryObject(TenantOrg.class, volume.getTenant().getURI());
tenantName = tenant.getLabel();
} catch (DatabaseException e) {
log.error("Error lookup TenantOrb object", e);
}
label = nameGenerator.generate(tenantName, volume.getLabel(), volume.getId().toString(), '-', HDSConstants.MAX_VOLUME_NAME_LENGTH);
}
if (capacity == null) {
capacity = volume.getCapacity();
}
isThinVolume = volume.getThinlyProvisioned();
}
log.info(logMsgBuilder.toString());
try {
multiVolumeCheckForHitachiModel(volumes, storageSystem);
HDSApiClient hdsApiClient = hdsApiFactory.getClient(HDSUtils.getHDSServerManagementServerInfo(storageSystem), storageSystem.getSmisUserName(), storageSystem.getSmisPassword());
String systemObjectID = HDSUtils.getSystemObjectID(storageSystem);
String poolObjectID = HDSUtils.getPoolObjectID(storagePool);
String asyncTaskMessageId = null;
// isThinVolume = false, creates LogicalUnits
if (isThinVolume) {
asyncTaskMessageId = hdsApiClient.createThinVolumes(systemObjectID, storagePool.getNativeId(), capacity, volumes.size(), label, QUICK_FORMAT_TYPE, storageSystem.getModel());
} else if (!isThinVolume) {
asyncTaskMessageId = hdsApiClient.createThickVolumes(systemObjectID, poolObjectID, capacity, volumes.size(), label, null, storageSystem.getModel(), null);
}
if (asyncTaskMessageId != null) {
HDSJob createHDSJob = (volumes.size() > 1) ? new HDSCreateMultiVolumeJob(asyncTaskMessageId, volumes.get(0).getStorageController(), storagePool.getId(), volumes.size(), taskCompleter) : new HDSCreateVolumeJob(asyncTaskMessageId, volumes.get(0).getStorageController(), storagePool.getId(), taskCompleter);
ControllerServiceImpl.enqueueJob(new QueueJob(createHDSJob));
} else {
throw HDSException.exceptions.asyncTaskFailed("Unable to get async taskId from HiCommand Device Manager for the create volume call");
}
} catch (final InternalException e) {
log.error("Problem in doCreateVolumes: ", e);
opCreationFailed = true;
taskCompleter.error(dbClient, e);
} catch (final Exception e) {
log.error("Problem in doCreateVolumes: ", e);
opCreationFailed = true;
ServiceError serviceError = DeviceControllerErrors.hds.methodFailed("doCreateVolumes", e.getMessage());
taskCompleter.error(dbClient, serviceError);
}
if (opCreationFailed) {
for (Volume vol : volumes) {
vol.setInactive(true);
dbClient.persistObject(vol);
}
}
logMsgBuilder = new StringBuilder(String.format("Create Volumes End - Array:%s, Pool:%s", storageSystem.getSerialNumber(), storagePool.getNativeGuid()));
for (Volume volume : volumes) {
logMsgBuilder.append(String.format("%nVolume:%s", volume.getLabel()));
}
log.info(logMsgBuilder.toString());
}
use of com.emc.storageos.db.client.model.TenantOrg in project coprhd-controller by CoprHD.
the class HDSBlockCreateSnapshotJob method changeSnapshotName.
/**
* Method will modify the name of a given volume to a generate name.
*
* @param dbClient [in] - Client instance for reading/writing from/to DB
* @param client [in] - HDSApiClient used for reading/writing from/to HiCommand DM.
* @param snapshotObj [in] - Volume object
*/
private void changeSnapshotName(DbClient dbClient, HDSApiClient client, BlockSnapshot snapshotObj) {
try {
Volume source = dbClient.queryObject(Volume.class, snapshotObj.getParent());
// Get the tenant name from the volume
TenantOrg tenant = dbClient.queryObject(TenantOrg.class, source.getTenant().getURI());
String tenantName = tenant.getLabel();
// that was successfully created
if (_nameGeneratorRef.get() == null) {
_nameGeneratorRef.compareAndSet(null, (NameGenerator) ControllerServiceImpl.getBean("defaultNameGenerator"));
}
String generatedName = _nameGeneratorRef.get().generate(tenantName, snapshotObj.getLabel(), snapshotObj.getId().toString(), '-', HDSConstants.MAX_VOLUME_NAME_LENGTH);
log.info(String.format("Attempting to add snapshot label %s to %s", generatedName, snapshotObj.getNativeId()));
StorageSystem system = dbClient.queryObject(StorageSystem.class, snapshotObj.getStorageController());
String systemObjectId = HDSUtils.getSystemObjectID(system);
LogicalUnit logicalUnit = client.getLogicalUnitInfo(systemObjectId, HDSUtils.getLogicalUnitObjectId(snapshotObj.getNativeId(), system));
if (null != logicalUnit && null != logicalUnit.getLdevList() && !logicalUnit.getLdevList().isEmpty()) {
Iterator<LDEV> ldevItr = logicalUnit.getLdevList().iterator();
if (ldevItr.hasNext()) {
LDEV ldev = ldevItr.next();
ObjectLabel objectLabel = client.addVolumeLabel(ldev.getObjectID(), generatedName);
snapshotObj.setDeviceLabel(objectLabel.getLabel());
dbClient.persistObject(snapshotObj);
}
} else {
log.info("No LDEV's found on volume: {}", snapshotObj.getNativeId());
}
log.info(String.format("snapshot label has been added to snapshot %s", snapshotObj.getNativeId()));
} catch (Exception e) {
log.error("Encountered an error while trying to set the snapshot name", e);
}
}
use of com.emc.storageos.db.client.model.TenantOrg in project coprhd-controller by CoprHD.
the class VPlexUtil method lookupVplexProject.
/**
* Lookup the Project assigned to this VPlex for its artifact, using the Vplex nativeGuid
* as the project name. If one is found thatbelongs to the root tenant, it is returned.
* Otherwise the project from the protoVolume is returned.
*
* @protoVolume A volume from the backend array.
* If no Vplex project is found, the proto volume's project is returned.
* @param vplexSystem A StorageSystem instance representing a VPlex.
* @param dbClient A reference to a database client.
*
* @return Project instance (vplex project if created, otherwise protoVolume's project).
*/
public static Project lookupVplexProject(Volume protoVolume, StorageSystem vplexSystem, DbClient dbClient) {
BasePermissionsHelper helper = new BasePermissionsHelper(dbClient);
TenantOrg rootTenant = helper.getRootTenant();
PrefixConstraint constraint = PrefixConstraint.Factory.getLabelPrefixConstraint(Project.class, vplexSystem.getNativeGuid());
URIQueryResultList result = new URIQueryResultList();
dbClient.queryByConstraint(constraint, result);
Iterator<URI> iter = result.iterator();
while (iter.hasNext()) {
Project project = dbClient.queryObject(Project.class, iter.next());
if (project == null || project.getInactive() == true) {
continue;
}
if (project.getLabel().equals(vplexSystem.getNativeGuid()) && project.getTenantOrg().getURI().toString().equals(rootTenant.getId().toString())) {
return project;
}
}
// VPlex project not found. Return on from proto volume.
return dbClient.queryObject(Project.class, protoVolume.getProject().getURI());
}
use of com.emc.storageos.db.client.model.TenantOrg in project coprhd-controller by CoprHD.
the class BasePermissionsHelper method getRootTenant.
/**
* Returns root TenantOrg
*
* @return
*/
public TenantOrg getRootTenant() {
if (_usingCache && QueriedObjectCache.getRootTenantOrgObject() != null) {
return QueriedObjectCache.getRootTenantOrgObject();
}
URIQueryResultList tenants = new URIQueryResultList();
try {
_dbClient.queryByConstraint(ContainmentConstraint.Factory.getTenantOrgSubTenantConstraint(URI.create(TenantOrg.NO_PARENT)), tenants);
if (tenants.iterator().hasNext()) {
URI root = tenants.iterator().next();
TenantOrg rootTenant = _dbClient.queryObject(TenantOrg.class, root);
QueriedObjectCache.setRootTenantObject(rootTenant);
// It is possible have multiple index entries for the same root tenant at a certain period (CQ610571)
while (tenants.iterator().hasNext()) {
URI mulRoot = tenants.iterator().next();
if (!mulRoot.equals(root)) {
_log.error("multiple entries found for root tenant. Stop.");
throw SecurityException.fatals.rootTenantQueryReturnedDuplicates();
}
}
return rootTenant;
} else {
_log.error("root tenant query returned no results");
}
} catch (DatabaseException ex) {
throw SecurityException.fatals.tenantQueryFailed(TenantOrg.NO_PARENT, ex);
}
throw SecurityException.fatals.tenantQueryFailed(TenantOrg.NO_PARENT);
}
Aggregations