use of com.emc.storageos.hds.model.ObjectLabel in project coprhd-controller by CoprHD.
the class HDSVolumeDiscoverer method getLabelFromLogicalUnit.
/**
* return the label of the LDEV if user is set else return null.
*
* @param logicalUnit
* @return
*/
private String getLabelFromLogicalUnit(LogicalUnit logicalUnit) {
String ldevLabel = null;
if (null != logicalUnit.getLdevList()) {
Iterator<LDEV> ldevItr = logicalUnit.getLdevList().iterator();
if (ldevItr.hasNext()) {
LDEV ldev = ldevItr.next();
ObjectLabel label = ldev.getLabel();
if (null != label) {
ldevLabel = label.getLabel();
}
}
}
return ldevLabel;
}
use of com.emc.storageos.hds.model.ObjectLabel in project coprhd-controller by CoprHD.
the class HDSApiVolumeManager method addLabelToObject.
/**
* Adds the label to an Object in DeviceManager.
* Currently this is supported for labeling LDEV.
* So, targetID must be a LDEV ID of a LU.
*
* @param targetID
* @param label
* @return
* @throws Exception
*/
public ObjectLabel addLabelToObject(String targetID, String label) throws Exception {
InputStream responseStream = null;
ObjectLabel objectLabel = null;
Map<String, Object> attributeMap = new HashMap<String, Object>();
Add addOp = new Add(HDSConstants.OBJECTLABEL);
addOp.setOverwrite(Boolean.TRUE);
attributeMap.put(HDSConstants.ADD, addOp);
ObjectLabel objectLabelReq = new ObjectLabel(targetID, label);
attributeMap.put(HDSConstants.OBJECTLABEL, objectLabelReq);
String addLabelToObject = InputXMLGenerationClient.getInputXMLString(HDSConstants.ADD_LABEL_TO_OBJECT_OP, attributeMap, HDSConstants.HITACHI_INPUT_XML_CONTEXT_FILE, HDSConstants.HITACHI_SMOOKS_CONFIG_FILE);
URI endpointURI = hdsApiClient.getBaseURI();
log.info("Add Label to Object payload :{}", addLabelToObject);
ClientResponse response = hdsApiClient.post(endpointURI, addLabelToObject);
if (HttpStatus.SC_OK == response.getStatus()) {
responseStream = response.getEntityInputStream();
JavaResult result = SmooksUtil.getParsedXMLJavaResult(responseStream, HDSConstants.SMOOKS_CONFIG_FILE);
verifyErrorPayload(result);
objectLabel = result.getBean(ObjectLabel.class);
} else {
log.error("Add label to Object failed with invalid response code {}", response.getStatus());
throw HDSException.exceptions.invalidResponseFromHDS(String.format("Not able to Add Label to object due to invalid response %1$s from server", response.getStatus()));
}
return objectLabel;
}
use of com.emc.storageos.hds.model.ObjectLabel in project coprhd-controller by CoprHD.
the class HDSAbstractCreateVolumeJob method changeVolumeName.
/**
* 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 volume [in] - Volume object
*/
protected void changeVolumeName(DbClient dbClient, HDSApiClient client, Volume volume, String name) {
try {
_log.info(String.format("Attempting to add volume label %s to %s", name, volume.getWWN()));
StorageSystem system = dbClient.queryObject(StorageSystem.class, volume.getStorageController());
String systemObjectId = HDSUtils.getSystemObjectID(system);
LogicalUnit logicalUnit = client.getLogicalUnitInfo(systemObjectId, HDSUtils.getLogicalUnitObjectId(volume.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(), name);
volume.setDeviceLabel(objectLabel.getLabel());
dbClient.persistObject(volume);
}
} else {
_log.info("No LDEV's found on volume: {}", volume.getWWN());
}
_log.info(String.format("Volume label has been added to volume %s", volume.getWWN()));
} catch (DatabaseException e) {
_log.error("Encountered an error while trying to set the volume name", e);
} catch (Exception e) {
_log.error("Encountered an error while trying to set the volume name", e);
}
}
use of com.emc.storageos.hds.model.ObjectLabel 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);
}
}
Aggregations