Search in sources :

Example 1 with ObjectLabel

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;
}
Also used : ObjectLabel(com.emc.storageos.hds.model.ObjectLabel) LDEV(com.emc.storageos.hds.model.LDEV)

Example 2 with ObjectLabel

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;
}
Also used : Add(com.emc.storageos.hds.model.Add) ClientResponse(com.sun.jersey.api.client.ClientResponse) ObjectLabel(com.emc.storageos.hds.model.ObjectLabel) HashMap(java.util.HashMap) InputStream(java.io.InputStream) URI(java.net.URI) JavaResult(org.milyn.payload.JavaResult)

Example 3 with 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);
    }
}
Also used : ObjectLabel(com.emc.storageos.hds.model.ObjectLabel) LogicalUnit(com.emc.storageos.hds.model.LogicalUnit) LDEV(com.emc.storageos.hds.model.LDEV) DatabaseException(com.emc.storageos.db.exceptions.DatabaseException) DatabaseException(com.emc.storageos.db.exceptions.DatabaseException) IOException(java.io.IOException) StorageSystem(com.emc.storageos.db.client.model.StorageSystem)

Example 4 with ObjectLabel

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);
    }
}
Also used : ObjectLabel(com.emc.storageos.hds.model.ObjectLabel) Volume(com.emc.storageos.db.client.model.Volume) LogicalUnit(com.emc.storageos.hds.model.LogicalUnit) TenantOrg(com.emc.storageos.db.client.model.TenantOrg) LDEV(com.emc.storageos.hds.model.LDEV) StorageSystem(com.emc.storageos.db.client.model.StorageSystem)

Aggregations

ObjectLabel (com.emc.storageos.hds.model.ObjectLabel)4 LDEV (com.emc.storageos.hds.model.LDEV)3 StorageSystem (com.emc.storageos.db.client.model.StorageSystem)2 LogicalUnit (com.emc.storageos.hds.model.LogicalUnit)2 TenantOrg (com.emc.storageos.db.client.model.TenantOrg)1 Volume (com.emc.storageos.db.client.model.Volume)1 DatabaseException (com.emc.storageos.db.exceptions.DatabaseException)1 Add (com.emc.storageos.hds.model.Add)1 ClientResponse (com.sun.jersey.api.client.ClientResponse)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 URI (java.net.URI)1 HashMap (java.util.HashMap)1 JavaResult (org.milyn.payload.JavaResult)1