Search in sources :

Example 6 with LogicalUnit

use of com.emc.storageos.hds.model.LogicalUnit in project coprhd-controller by CoprHD.

the class HDSVolumeExpandJob method updateStatus.

/**
 * Called to update the job status when the volume expand job completes.
 *
 * @param jobContext
 *            The job context.
 */
@Override
public void updateStatus(JobContext jobContext) throws Exception {
    LogicalUnit logicalUnit = null;
    try {
        if (_status == JobStatus.IN_PROGRESS) {
            return;
        }
        DbClient dbClient = jobContext.getDbClient();
        StorageSystem storageSystem = dbClient.queryObject(StorageSystem.class, getStorageSystemURI());
        HDSApiClient hdsApiClient = jobContext.getHdsApiFactory().getClient(HDSUtils.getHDSServerManagementServerInfo(storageSystem), storageSystem.getSmisUserName(), storageSystem.getSmisPassword());
        // from pool's reserved capacity map.
        if (_status == JobStatus.SUCCESS || _status == JobStatus.FAILED) {
            StoragePool storagePool = dbClient.queryObject(StoragePool.class, storagePoolURI);
            HDSUtils.updateStoragePoolCapacity(dbClient, hdsApiClient, storagePool);
            StringMap reservationMap = storagePool.getReservedCapacityMap();
            URI volumeId = getTaskCompleter().getId();
            // remove from reservation map
            reservationMap.remove(volumeId.toString());
            dbClient.persistObject(storagePool);
        }
        String opId = getTaskCompleter().getOpId();
        StringBuilder logMsgBuilder = new StringBuilder(String.format("Updating status of job %s to %s, task: %s", this.getJobName(), _status.name(), opId));
        if (_status == JobStatus.SUCCESS) {
            VolumeExpandCompleter taskCompleter = (VolumeExpandCompleter) getTaskCompleter();
            Volume volume = dbClient.queryObject(Volume.class, taskCompleter.getId());
            // set requested capacity
            volume.setCapacity(taskCompleter.getSize());
            // set meta related properties
            volume.setIsComposite(taskCompleter.isComposite());
            volume.setCompositionType(taskCompleter.getMetaVolumeType());
            logicalUnit = (LogicalUnit) _javaResult.getBean("logicalunit");
            if (null != logicalUnit) {
                long capacityInBytes = (Long.valueOf(logicalUnit.getCapacityInKB())) * 1024L;
                volume.setProvisionedCapacity(capacityInBytes);
                volume.setAllocatedCapacity(capacityInBytes);
            }
            logMsgBuilder.append(String.format("%n   Capacity: %s, Provisioned capacity: %s, Allocated Capacity: %s", volume.getCapacity(), volume.getProvisionedCapacity(), volume.getAllocatedCapacity()));
            if (volume.getIsComposite()) {
                logMsgBuilder.append(String.format("%n  Is Meta: %s, Total meta member capacity: %s, Meta member count %s, Meta member size: %s", volume.getIsComposite(), volume.getTotalMetaMemberCapacity(), volume.getMetaMemberCount(), volume.getMetaMemberSize()));
            }
            _log.info(logMsgBuilder.toString());
            dbClient.persistObject(volume);
            // Reset list of meta members native ids in WF data (when meta
            // is created meta members are removed from array)
            WorkflowService.getInstance().storeStepData(opId, new ArrayList<String>());
        }
    } catch (Exception e) {
        _log.error("Caught an exception while trying to updateStatus for HDSVolumeExpandJob", e);
        setErrorStatus("Encountered an internal error during volume expand job status processing : " + e.getMessage());
    } finally {
        super.updateStatus(jobContext);
    }
}
Also used : HDSApiClient(com.emc.storageos.hds.api.HDSApiClient) StringMap(com.emc.storageos.db.client.model.StringMap) DbClient(com.emc.storageos.db.client.DbClient) StoragePool(com.emc.storageos.db.client.model.StoragePool) VolumeExpandCompleter(com.emc.storageos.volumecontroller.impl.block.taskcompleter.VolumeExpandCompleter) LogicalUnit(com.emc.storageos.hds.model.LogicalUnit) URI(java.net.URI) Volume(com.emc.storageos.db.client.model.Volume) StorageSystem(com.emc.storageos.db.client.model.StorageSystem)

Example 7 with LogicalUnit

use of com.emc.storageos.hds.model.LogicalUnit in project coprhd-controller by CoprHD.

the class HDSApiVolumeManager method deleteSnapshotVolume.

public String deleteSnapshotVolume(String storageSystemObjId, String logicalUnitObjId, String model) throws Exception {
    String asyncTaskMessageId = null;
    InputStream responseStream = null;
    try {
        if (null != storageSystemObjId && null != logicalUnitObjId) {
            log.info("Deleting snapshot with id {} from Storage System {}", logicalUnitObjId, storageSystemObjId);
            Map<String, Object> attributeMap = new HashMap<String, Object>();
            Delete deleteOp = new Delete(HDSConstants.VIRTUALVOLUME);
            StorageArray storageArray = new StorageArray(storageSystemObjId);
            LogicalUnit logicalUnit = new LogicalUnit();
            logicalUnit.setObjectID(logicalUnitObjId);
            attributeMap.put(HDSConstants.DELETE, deleteOp);
            attributeMap.put(HDSConstants.MODEL, model);
            attributeMap.put(HDSConstants.STORAGEARRAY, storageArray);
            attributeMap.put(HDSConstants.LOGICALUNIT, logicalUnit);
            String createSnapshotInputXML = InputXMLGenerationClient.getInputXMLString(HDSConstants.DELETE_SNAPSHOT_VOLUME_OP, attributeMap, HDSConstants.HITACHI_INPUT_XML_CONTEXT_FILE, HDSConstants.HITACHI_SMOOKS_CONFIG_FILE);
            log.info("Query to delete snapshot Volume: {}", createSnapshotInputXML);
            URI endpointURI = hdsApiClient.getBaseURI();
            ClientResponse response = hdsApiClient.post(endpointURI, createSnapshotInputXML);
            if (HttpStatus.SC_OK == response.getStatus()) {
                responseStream = response.getEntityInputStream();
                JavaResult result = SmooksUtil.getParsedXMLJavaResult(responseStream, HDSConstants.SMOOKS_CONFIG_FILE);
                EchoCommand command = result.getBean(EchoCommand.class);
                log.info("command Status :{} MessageId :{}", command.getStatus(), command.getMessageID());
                if (HDSConstants.PROCESSING_STR.equalsIgnoreCase(command.getStatus()) || HDSConstants.COMPLETED_STR.equalsIgnoreCase(command.getStatus())) {
                    asyncTaskMessageId = command.getMessageID();
                } else if (HDSConstants.FAILED_STR.equalsIgnoreCase(command.getStatus())) {
                    Error error = result.getBean(Error.class);
                    log.error("Snapshot volume deletion failed status messageID: {}", command.getMessageID());
                    log.error("Snapshot volume failed with error code: {} with message: {}", error.getCode(), error.getDescription());
                    throw HDSException.exceptions.notAbleToDeleteSnapshot(error.getCode(), error.getDescription());
                }
            } else {
                log.error("Snapshot deletion failed with invalid response code {}", response.getStatus());
                throw HDSException.exceptions.invalidResponseFromHDS(String.format("Snapshot deletion failed due to invalid response %1$s from server for system %2$s", response.getStatus(), storageSystemObjId));
            }
            log.info("Snapshot with id {} deleted from Storage System {}", logicalUnitObjId, storageSystemObjId);
        }
    } finally {
        if (null != responseStream) {
            try {
                responseStream.close();
            } catch (IOException e) {
                log.warn("Exception occurred while closing snapshot deletion response stream");
            }
        }
    }
    return asyncTaskMessageId;
}
Also used : Delete(com.emc.storageos.hds.model.Delete) ClientResponse(com.sun.jersey.api.client.ClientResponse) HashMap(java.util.HashMap) InputStream(java.io.InputStream) LogicalUnit(com.emc.storageos.hds.model.LogicalUnit) Error(com.emc.storageos.hds.model.Error) IOException(java.io.IOException) URI(java.net.URI) JavaResult(org.milyn.payload.JavaResult) EchoCommand(com.emc.storageos.hds.model.EchoCommand) StorageArray(com.emc.storageos.hds.model.StorageArray)

Example 8 with LogicalUnit

use of com.emc.storageos.hds.model.LogicalUnit in project coprhd-controller by CoprHD.

the class HDSApiVolumeManager method getLogicalUnitInfo.

/**
 * Return the LogicalUnit info for the given logicalUnitObjectId.
 *
 * @param systemObjectId
 * @param logicalUnitObjectId
 * @return
 * @throws Exception
 */
public LogicalUnit getLogicalUnitInfo(String systemObjectId, String logicalUnitObjectId) throws Exception {
    InputStream responseStream = null;
    LogicalUnit logicalUnit = null;
    Map<String, Object> attributeMap = new HashMap<String, Object>();
    StorageArray storageArray = new StorageArray(systemObjectId);
    Get getOp = new Get(HDSConstants.STORAGEARRAY);
    attributeMap.put(HDSConstants.STORAGEARRAY, storageArray);
    attributeMap.put(HDSConstants.GET, getOp);
    LogicalUnit lu = new LogicalUnit(logicalUnitObjectId, null);
    attributeMap.put(HDSConstants.LOGICALUNIT, lu);
    String getLogicalUnitsInputXML = InputXMLGenerationClient.getInputXMLString(HDSConstants.GET_LOGICALUNITS_OP, attributeMap, HDSConstants.HITACHI_INPUT_XML_CONTEXT_FILE, HDSConstants.HITACHI_SMOOKS_CONFIG_FILE);
    URI endpointURI = hdsApiClient.getBaseURI();
    log.info("Volume info query payload :{}", getLogicalUnitsInputXML);
    ClientResponse response = hdsApiClient.post(endpointURI, getLogicalUnitsInputXML);
    if (HttpStatus.SC_OK == response.getStatus()) {
        responseStream = response.getEntityInputStream();
        JavaResult result = SmooksUtil.getParsedXMLJavaResult(responseStream, HDSConstants.SMOOKS_CONFIG_FILE);
        verifyErrorPayload(result);
        logicalUnit = (LogicalUnit) result.getBean(HDSConstants.LOGICALUNIT_BEAN_NAME);
    } else {
        log.error("Get LogicalUnit info failed with invalid response code {}", response.getStatus());
        throw HDSException.exceptions.invalidResponseFromHDS(String.format("Not able to query LogicalUnit info due to invalid response %1$s from server for system %2$s", response.getStatus(), systemObjectId));
    }
    return logicalUnit;
}
Also used : ClientResponse(com.sun.jersey.api.client.ClientResponse) HashMap(java.util.HashMap) InputStream(java.io.InputStream) LogicalUnit(com.emc.storageos.hds.model.LogicalUnit) Get(com.emc.storageos.hds.model.Get) URI(java.net.URI) JavaResult(org.milyn.payload.JavaResult) StorageArray(com.emc.storageos.hds.model.StorageArray)

Example 9 with LogicalUnit

use of com.emc.storageos.hds.model.LogicalUnit in project coprhd-controller by CoprHD.

the class HDSApiVolumeManager method getAllLogicalUnits.

/**
 * Returns all LogicalUnits of a given system.
 *
 * @param systemObjectId
 * @return
 */
public List<LogicalUnit> getAllLogicalUnits(String systemObjectId) throws Exception {
    InputStream responseStream = null;
    List<LogicalUnit> luList = null;
    Map<String, Object> attributeMap = new HashMap<String, Object>();
    StorageArray storageArray = new StorageArray(systemObjectId);
    attributeMap.put(HDSConstants.STORAGEARRAY, storageArray);
    Get getOp = new Get(HDSConstants.STORAGEARRAY);
    attributeMap.put(HDSConstants.GET, getOp);
    LogicalUnit lu = new LogicalUnit();
    attributeMap.put(HDSConstants.LOGICALUNIT, lu);
    String getLogicalUnitsInputXML = InputXMLGenerationClient.getInputXMLString(HDSConstants.GET_LOGICALUNITS_OP, attributeMap, HDSConstants.HITACHI_INPUT_XML_CONTEXT_FILE, HDSConstants.HITACHI_SMOOKS_CONFIG_FILE);
    URI endpointURI = hdsApiClient.getBaseURI();
    log.info("Get all LogicalUnits query payload :{}", getLogicalUnitsInputXML);
    ClientResponse response = hdsApiClient.post(endpointURI, getLogicalUnitsInputXML);
    if (HttpStatus.SC_OK == response.getStatus()) {
        responseStream = response.getEntityInputStream();
        JavaResult result = SmooksUtil.getParsedXMLJavaResult(responseStream, HDSConstants.SMOOKS_CONFIG_FILE);
        verifyErrorPayload(result);
        luList = (List<LogicalUnit>) result.getBean(HDSConstants.LOGICALUNIT_LIST_BEAN_NAME);
    } else {
        log.error("Get all LogicalUnits failed with invalid response code {}", response.getStatus());
        throw HDSException.exceptions.invalidResponseFromHDS(String.format("Not able to query all LogicalUnits due to invalid response %1$s from server for system %2$s", response.getStatus(), systemObjectId));
    }
    return luList;
}
Also used : ClientResponse(com.sun.jersey.api.client.ClientResponse) HashMap(java.util.HashMap) InputStream(java.io.InputStream) LogicalUnit(com.emc.storageos.hds.model.LogicalUnit) Get(com.emc.storageos.hds.model.Get) URI(java.net.URI) JavaResult(org.milyn.payload.JavaResult) StorageArray(com.emc.storageos.hds.model.StorageArray)

Example 10 with LogicalUnit

use of com.emc.storageos.hds.model.LogicalUnit in project coprhd-controller by CoprHD.

the class HDSApiVolumeManager method formatLogicalUnit.

/**
 * Formats the LogicalUnit.
 *
 * @param systemObjectId
 * @param luObjectId
 * @return
 */
public String formatLogicalUnit(String systemObjectId, String luObjectId) {
    InputStream responseStream = null;
    String asyncTaskMessageId = null;
    try {
        Map<String, Object> attributeMap = new HashMap<String, Object>();
        StorageArray storageArray = new StorageArray(systemObjectId);
        Modify modifyOp = new Modify(HDSConstants.LU_FORMAT_TARGET, true);
        LogicalUnit logicalUnit = new LogicalUnit(luObjectId, null);
        attributeMap.put(HDSConstants.STORAGEARRAY, storageArray);
        attributeMap.put(HDSConstants.MODIFY, modifyOp);
        attributeMap.put(HDSConstants.LOGICALUNIT, logicalUnit);
        String fromatVolumeInputXML = InputXMLGenerationClient.getInputXMLString(HDSConstants.FORMAT_VOLUME_OP, attributeMap, HDSConstants.HITACHI_INPUT_XML_CONTEXT_FILE, HDSConstants.HITACHI_SMOOKS_CONFIG_FILE);
        log.info("Query to format LogicalUnit: {}", fromatVolumeInputXML);
        URI endpointURI = hdsApiClient.getBaseURI();
        ClientResponse response = hdsApiClient.post(endpointURI, fromatVolumeInputXML);
        if (HttpStatus.SC_OK == response.getStatus()) {
            responseStream = response.getEntityInputStream();
            JavaResult result = SmooksUtil.getParsedXMLJavaResult(responseStream, HDSConstants.SMOOKS_CONFIG_FILE);
            EchoCommand command = result.getBean(EchoCommand.class);
            log.info("command Status :{} MessageId :{}", command.getStatus(), command.getMessageID());
            if (HDSConstants.PROCESSING_STR.equalsIgnoreCase(command.getStatus()) || HDSConstants.COMPLETED_STR.equalsIgnoreCase(command.getStatus())) {
                asyncTaskMessageId = command.getMessageID();
            } else if (HDSConstants.FAILED_STR.equalsIgnoreCase(command.getStatus())) {
                Error error = result.getBean(Error.class);
                log.error("Query to format LogicalUnit: failed status messageID: {}", command.getMessageID());
                log.error("LogicalUnit formatting failed with error code: {} with message: {}", error.getCode(), error.getDescription());
                throw HDSException.exceptions.notAbleToCreateVolume(error.getCode(), error.getDescription());
            }
        } else {
            log.error("LogicalUnit format failed with invalid response code {}", response.getStatus());
            throw HDSException.exceptions.invalidResponseFromHDS(String.format("LogicalUnit format failed due to invalid response %1$s from server for system %2$s", response.getStatus(), systemObjectId));
        }
    } finally {
        if (null != responseStream) {
            try {
                responseStream.close();
            } catch (IOException e) {
                log.warn("Exception occurred while closing Formatting LogicalUnit response stream");
            }
        }
    }
    return asyncTaskMessageId;
}
Also used : ClientResponse(com.sun.jersey.api.client.ClientResponse) HashMap(java.util.HashMap) InputStream(java.io.InputStream) LogicalUnit(com.emc.storageos.hds.model.LogicalUnit) Error(com.emc.storageos.hds.model.Error) Modify(com.emc.storageos.hds.model.Modify) IOException(java.io.IOException) URI(java.net.URI) JavaResult(org.milyn.payload.JavaResult) EchoCommand(com.emc.storageos.hds.model.EchoCommand) StorageArray(com.emc.storageos.hds.model.StorageArray)

Aggregations

LogicalUnit (com.emc.storageos.hds.model.LogicalUnit)27 URI (java.net.URI)18 ClientResponse (com.sun.jersey.api.client.ClientResponse)13 InputStream (java.io.InputStream)13 HashMap (java.util.HashMap)13 JavaResult (org.milyn.payload.JavaResult)13 StorageArray (com.emc.storageos.hds.model.StorageArray)12 IOException (java.io.IOException)12 HDSApiClient (com.emc.storageos.hds.api.HDSApiClient)10 EchoCommand (com.emc.storageos.hds.model.EchoCommand)9 Error (com.emc.storageos.hds.model.Error)9 LDEV (com.emc.storageos.hds.model.LDEV)7 ArrayList (java.util.ArrayList)7 StorageSystem (com.emc.storageos.db.client.model.StorageSystem)6 Volume (com.emc.storageos.db.client.model.Volume)6 DatabaseException (com.emc.storageos.db.exceptions.DatabaseException)5 DeviceControllerException (com.emc.storageos.exceptions.DeviceControllerException)5 HDSException (com.emc.storageos.hds.HDSException)5 ServiceError (com.emc.storageos.svcs.errorhandling.model.ServiceError)5 QueueJob (com.emc.storageos.volumecontroller.impl.job.QueueJob)5