Search in sources :

Example 11 with HostStorageDomain

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

the class HDSApiExportManager method constructRemoveISCSIQuery.

/**
 * Construct the iSCSINames Query by adding multiple WWNs.
 * This query should be used to add the iSCSI initiators to the iSCSI HSD.
 *
 * @param systemId
 * @param hsdId
 * @param wwnList
 * @return
 */
private String constructRemoveISCSIQuery(String systemId, String hsdId, List<String> scsiNameList, String model) {
    Map<String, Object> attributeMap = new HashMap<String, Object>();
    StorageArray array = new StorageArray(systemId);
    Delete deleteOp = new Delete(HDSConstants.ISCSI_NAME_FOR_HSD_TARGET);
    attributeMap.put(HDSConstants.STORAGEARRAY, array);
    attributeMap.put(HDSConstants.DELETE, deleteOp);
    attributeMap.put(HDSConstants.MODEL, model);
    HostStorageDomain hsd = new HostStorageDomain(hsdId);
    attributeMap.put(HDSConstants.HOST_STORAGE_DOMAIN, hsd);
    List<ISCSIName> iSCSIObjList = new ArrayList<ISCSIName>();
    if (null != scsiNameList && !scsiNameList.isEmpty()) {
        for (String iScsiName : scsiNameList) {
            ISCSIName iSCSIName = new ISCSIName(iScsiName, null);
            iSCSIObjList.add(iSCSIName);
        }
    }
    attributeMap.put(HDSConstants.ISCSINAME_LIST, iSCSIObjList);
    String removeISCSINamesToHSDQuery = InputXMLGenerationClient.getInputXMLString(HDSConstants.REMOVE_ISCSI_NAME_FROM_HSD_OP, attributeMap, HDSConstants.HITACHI_INPUT_XML_CONTEXT_FILE, HDSConstants.HITACHI_SMOOKS_CONFIG_FILE);
    return removeISCSINamesToHSDQuery;
}
Also used : Delete(com.emc.storageos.hds.model.Delete) HashMap(java.util.HashMap) HostStorageDomain(com.emc.storageos.hds.model.HostStorageDomain) ISCSIName(com.emc.storageos.hds.model.ISCSIName) ArrayList(java.util.ArrayList) StorageArray(com.emc.storageos.hds.model.StorageArray)

Example 12 with HostStorageDomain

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

the class HDSApiExportManager method getFreeLUNInfo.

/**
 * Return the Free Lun's available for a Given HSD in a System.
 *
 * @throws Exception
 */
public List<FreeLun> getFreeLUNInfo(String systemId, String hsdId) throws Exception {
    InputStream responseStream = null;
    HostStorageDomain hostStorageDomain = null;
    List<FreeLun> freeLunList = null;
    try {
        Map<String, Object> attributeMap = new HashMap<String, Object>();
        StorageArray array = new StorageArray(systemId);
        Get getOp = new Get(HDSConstants.STORAGEARRAY);
        attributeMap.put(HDSConstants.STORAGEARRAY, array);
        HostStorageDomain hsd = new HostStorageDomain(hsdId);
        FreeLun freeLun = new FreeLun();
        attributeMap.put(HDSConstants.GET, getOp);
        attributeMap.put(HDSConstants.HOST_STORAGE_DOMAIN, hsd);
        attributeMap.put(HDSConstants.FREELUN, freeLun);
        String getFreeLunQueryInputXML = InputXMLGenerationClient.getInputXMLString(HDSConstants.GET_FREE_LUN_INFO_OP, attributeMap, HDSConstants.HITACHI_INPUT_XML_CONTEXT_FILE, HDSConstants.HITACHI_SMOOKS_CONFIG_FILE);
        log.info("Query to get FreeLUN's of a HostStorageDomain: {}", getFreeLunQueryInputXML);
        URI endpointURI = hdsApiClient.getBaseURI();
        ClientResponse response = hdsApiClient.post(endpointURI, getFreeLunQueryInputXML);
        if (HttpStatus.SC_OK == response.getStatus()) {
            responseStream = response.getEntityInputStream();
            JavaResult javaResult = SmooksUtil.getParsedXMLJavaResult(responseStream, HDSConstants.SMOOKS_CONFIG_FILE);
            verifyErrorPayload(javaResult);
            hostStorageDomain = javaResult.getBean(HostStorageDomain.class);
            if (null != hostStorageDomain && null != hostStorageDomain.getFreeLunList()) {
                freeLunList = hostStorageDomain.getFreeLunList();
            } else {
                throw HDSException.exceptions.notAbleToGetFreeLunInfoForHSD(hsdId, systemId);
            }
        } else {
            throw HDSException.exceptions.invalidResponseFromHDS(String.format("Not able to get FreeLun info for HostStorageDomain due to invalid response %1$s from server", response.getStatus()));
        }
    } finally {
        if (null != responseStream) {
            try {
                responseStream.close();
            } catch (IOException e) {
                log.warn("IOException occurred while closing the response stream");
            }
        }
    }
    return freeLunList;
}
Also used : ClientResponse(com.sun.jersey.api.client.ClientResponse) FreeLun(com.emc.storageos.hds.model.FreeLun) HashMap(java.util.HashMap) InputStream(java.io.InputStream) IOException(java.io.IOException) URI(java.net.URI) HostStorageDomain(com.emc.storageos.hds.model.HostStorageDomain) Get(com.emc.storageos.hds.model.Get) JavaResult(org.milyn.payload.JavaResult) StorageArray(com.emc.storageos.hds.model.StorageArray)

Example 13 with HostStorageDomain

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

the class HDSBatchApiExportManager method addHostStorageDomains.

/**
 * This method makes http POST call with a payload of bulk
 * HostStorageDomains.
 *
 * @param systemId
 *            - SystemObjectID.
 * @param hostGroups
 *            - List of HostStorageDomain objects.
 * @return - Returns a List of created HostStorageDomain on Array.
 * @throws Exception
 *             - In case processing errors.
 */
public List<HostStorageDomain> addHostStorageDomains(String systemId, List<HostStorageDomain> hostGroups, String model) throws Exception {
    InputStream responseStream = null;
    List<HostStorageDomain> hsdList = null;
    try {
        Map<String, Object> attributeMap = new HashMap<String, Object>();
        StorageArray array = new StorageArray(systemId);
        Add addOp = new Add(HDSConstants.HOST_STORAGE_DOMAIN);
        attributeMap.put(HDSConstants.STORAGEARRAY, array);
        attributeMap.put(HDSConstants.ADD, addOp);
        attributeMap.put(HDSConstants.MODEL, model);
        attributeMap.put(HDSConstants.HOSTGROUP_LIST, hostGroups);
        String addHSDToSystemQuery = InputXMLGenerationClient.getInputXMLString(HDSConstants.BATCH_ADD_HSDS_TO_SYSTEM_OP, attributeMap, HDSConstants.HITACHI_INPUT_XML_CONTEXT_FILE, HDSConstants.HITACHI_SMOOKS_CONFIG_FILE);
        log.info("Batch query to create HostStorageDomains: {}", addHSDToSystemQuery);
        URI endpointURI = hdsApiClient.getBaseURI();
        ClientResponse response = hdsApiClient.post(endpointURI, addHSDToSystemQuery);
        if (HttpStatus.SC_OK == response.getStatus()) {
            responseStream = response.getEntityInputStream();
            JavaResult javaResult = SmooksUtil.getParsedXMLJavaResult(responseStream, HDSConstants.SMOOKS_CONFIG_FILE);
            verifyErrorPayload(javaResult);
            hsdList = (List<HostStorageDomain>) javaResult.getBean(HDSConstants.HSD_RESPONSE_BEAN_ID);
            if (null == hsdList || hsdList.isEmpty()) {
                throw HDSException.exceptions.notAbleToAddHSD(systemId);
            }
        } else {
            throw HDSException.exceptions.invalidResponseFromHDS(String.format("Not able to add HostStorageDomains due to invalid response %1$s from server", response.getStatus()));
        }
    } finally {
        if (null != responseStream) {
            try {
                responseStream.close();
            } catch (IOException e) {
                log.warn("IOException occurred while closing the response stream addHostStorageDomains");
            }
        }
    }
    return hsdList;
}
Also used : Add(com.emc.storageos.hds.model.Add) ClientResponse(com.sun.jersey.api.client.ClientResponse) HashMap(java.util.HashMap) InputStream(java.io.InputStream) IOException(java.io.IOException) URI(java.net.URI) HostStorageDomain(com.emc.storageos.hds.model.HostStorageDomain) JavaResult(org.milyn.payload.JavaResult) StorageArray(com.emc.storageos.hds.model.StorageArray)

Example 14 with HostStorageDomain

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

the class HDSBatchApiExportManager method deleteBatchHostStorageDomains.

/**
 * This method makes a HTTP POST call to delete all HostStorageDomain's
 * using a batch query.
 *
 * @param systemId
 *            - Represents storage system ObjectID.
 * @param hsdList
 *            - List of HostStorageDomain objects to delete.
 * @param model - Model of the system
 *
 * @throws Exception
 */
public void deleteBatchHostStorageDomains(String systemId, List<HostStorageDomain> hsdList, String model) throws Exception {
    InputStream responseStream = null;
    try {
        List<HostStorageDomain> unDeletedHSDs = new ArrayList<>();
        unDeletedHSDs.addAll(hsdList);
        boolean operationSucceeds = false;
        int retryCount = 0;
        StringBuilder errorDescriptionBuilder = new StringBuilder();
        while (!operationSucceeds && retryCount < MAX_RETRIES) {
            retryCount++;
            String deleteHSDsQuery = constructDeleteHSDsQuery(systemId, unDeletedHSDs, model);
            log.info("Batch Query to delete HSD's: {}", deleteHSDsQuery);
            URI endpointURI = hdsApiClient.getBaseURI();
            ClientResponse response = hdsApiClient.post(endpointURI, deleteHSDsQuery);
            if (HttpStatus.SC_OK == response.getStatus()) {
                responseStream = response.getEntityInputStream();
                JavaResult javaResult = SmooksUtil.getParsedXMLJavaResult(responseStream, HDSConstants.SMOOKS_CONFIG_FILE);
                try {
                    verifyErrorPayload(javaResult);
                    // If no exception then operation succeeds
                    operationSucceeds = true;
                } catch (HDSException hdsException) {
                    Error error = javaResult.getBean(Error.class);
                    if (error != null && (error.getDescription().contains("2010") || error.getDescription().contains("5132") || error.getDescription().contains("7473"))) {
                        log.error("Error response recieved from HiCommandManger: {}", error.getDescription());
                        log.info("Exception from HICommand Manager recieved during delete operation, retrying operation {} time", retryCount);
                        errorDescriptionBuilder.append("error ").append(retryCount).append(" : ").append(error.getDescription()).append("-#####-");
                        // Wait for a minute before retry
                        Thread.sleep(60000);
                        unDeletedHSDs.clear();
                        unDeletedHSDs.addAll(hsdList.stream().filter(hsd -> getHostStorageDomain(systemId, hsd.getObjectID()) != null).collect(Collectors.toList()));
                        if (unDeletedHSDs.isEmpty()) {
                            // Operation succeeded
                            operationSucceeds = true;
                            log.info("Deleted {} LUN paths from system:{}", hsdList.size(), systemId);
                        } else {
                            // Retry the operation again if retry count not exceeded
                            continue;
                        }
                    } else {
                        throw HDSException.exceptions.invalidResponseFromHDS(String.format("Not able to delete HostStorageDomains due to invalid response from server. Error Code - %s Error Message - %s", error.getCode(), error.getDescription()));
                    }
                }
            } else {
                throw HDSException.exceptions.invalidResponseFromHDS(String.format("Not able to delete HostStorageDomains due to invalid response %1$s from server", response.getStatus()));
            }
        }
        if (!operationSucceeds) {
            // Delete operation failed ever after repeated retries
            throw HDSException.exceptions.invalidResponseFromHDS(String.format("Not able to delete HostStorageDomains due to repeated errors from HiCommand server, errors description are as %s", errorDescriptionBuilder.toString()));
        }
    } finally {
        if (null != responseStream) {
            try {
                responseStream.close();
            } catch (IOException e) {
                log.warn("IOException occurred while closing the response stream");
            }
        }
    }
    log.info("Batch Query to delete HSD's completed.");
}
Also used : ClientResponse(com.sun.jersey.api.client.ClientResponse) Logger(org.slf4j.Logger) ClientResponse(com.sun.jersey.api.client.ClientResponse) LoggerFactory(org.slf4j.LoggerFactory) HttpStatus(org.apache.http.HttpStatus) IOException(java.io.IOException) HashMap(java.util.HashMap) EchoCommand(com.emc.storageos.hds.model.EchoCommand) StorageArray(com.emc.storageos.hds.model.StorageArray) Collectors(java.util.stream.Collectors) HDSConstants(com.emc.storageos.hds.HDSConstants) JavaResult(org.milyn.payload.JavaResult) Path(com.emc.storageos.hds.model.Path) ArrayList(java.util.ArrayList) HDSException(com.emc.storageos.hds.HDSException) List(java.util.List) Error(com.emc.storageos.hds.model.Error) Map(java.util.Map) InputXMLGenerationClient(com.emc.storageos.hds.xmlgen.InputXMLGenerationClient) URI(java.net.URI) Delete(com.emc.storageos.hds.model.Delete) HostStorageDomain(com.emc.storageos.hds.model.HostStorageDomain) InputStream(java.io.InputStream) Add(com.emc.storageos.hds.model.Add) SmooksUtil(com.emc.storageos.hds.util.SmooksUtil) InputStream(java.io.InputStream) ArrayList(java.util.ArrayList) Error(com.emc.storageos.hds.model.Error) IOException(java.io.IOException) URI(java.net.URI) HostStorageDomain(com.emc.storageos.hds.model.HostStorageDomain) JavaResult(org.milyn.payload.JavaResult) HDSException(com.emc.storageos.hds.HDSException)

Example 15 with HostStorageDomain

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

the class HDSExportMaskInitiatorsValidator method validate.

@Override
public boolean validate() throws Exception {
    log.info("Initiating initiators validation of HDS ExportMask: {}", id);
    try {
        ExportMask exportMask = getExportMask();
        StorageSystem system = getStorage();
        if (exportMask != null && !CollectionUtils.isEmpty(exportMask.getDeviceDataMap())) {
            Set<String> hsdList = exportMask.getDeviceDataMap().keySet();
            HDSApiClient client = getClientFactory().getClient(HDSUtils.getHDSServerManagementServerInfo(system), system.getSmisUserName(), system.getSmisPassword());
            HDSApiExportManager exportManager = client.getHDSApiExportManager();
            String maskName = null;
            String systemObjectID = HDSUtils.getSystemObjectID(system);
            Set<String> volumesInExportMask = new HashSet<>();
            Set<String> initiatorsInExportMask = new HashSet<>();
            if (!CollectionUtils.isEmpty(exportMask.getUserAddedVolumes())) {
                volumesInExportMask.addAll(exportMask.getUserAddedVolumes().keySet());
            }
            if (!CollectionUtils.isEmpty(exportMask.getUserAddedInitiators())) {
                initiatorsInExportMask.addAll(exportMask.getUserAddedInitiators().keySet());
            }
            log.info("Volumes {} in Export Mask {}", volumesInExportMask, exportMask.forDisplay());
            log.info("Initiators {} in Export Mask {}", initiatorsInExportMask, exportMask.forDisplay());
            for (String hsdObjectIdFromDb : hsdList) {
                Set<String> discoveredVolumes = new HashSet<>();
                HostStorageDomain hsd = exportManager.getHostStorageDomain(systemObjectID, hsdObjectIdFromDb);
                if (null == hsd) {
                    continue;
                }
                maskName = (null == hsd.getName()) ? hsd.getNickname() : hsd.getName();
                // Get volumes and initiators from storage system
                discoveredVolumes.addAll(HDSUtils.getVolumesFromHSD(hsd, system).keySet());
                log.info("Volumes {} discovered from array for the HSD {}", discoveredVolumes, maskName);
                Set<String> additionalVolumesOnArray = Sets.difference(discoveredVolumes, volumesInExportMask);
                if (!CollectionUtils.isEmpty(additionalVolumesOnArray)) {
                    getValidatorLogger().logDiff(String.format("%s - %s", id, maskName), "volumes", ValidatorLogger.NO_MATCHING_ENTRY, Joiner.on("\t").join(additionalVolumesOnArray));
                }
            }
            checkForErrors();
        }
    } catch (Exception ex) {
        log.error("Unexpected exception validating ExportMask initiators: " + ex.getMessage(), ex);
        if (getValidatorConfig().isValidationEnabled()) {
            throw DeviceControllerException.exceptions.unexpectedCondition("Unexpected exception validating ExportMask initiators: " + ex.getMessage());
        }
    }
    return true;
}
Also used : HDSApiClient(com.emc.storageos.hds.api.HDSApiClient) HostStorageDomain(com.emc.storageos.hds.model.HostStorageDomain) ExportMask(com.emc.storageos.db.client.model.ExportMask) HDSApiExportManager(com.emc.storageos.hds.api.HDSApiExportManager) DeviceControllerException(com.emc.storageos.exceptions.DeviceControllerException) StorageSystem(com.emc.storageos.db.client.model.StorageSystem) HashSet(java.util.HashSet)

Aggregations

HostStorageDomain (com.emc.storageos.hds.model.HostStorageDomain)35 URI (java.net.URI)18 HashMap (java.util.HashMap)17 ArrayList (java.util.ArrayList)16 HDSApiClient (com.emc.storageos.hds.api.HDSApiClient)12 DeviceControllerException (com.emc.storageos.exceptions.DeviceControllerException)11 HDSApiExportManager (com.emc.storageos.hds.api.HDSApiExportManager)11 StorageArray (com.emc.storageos.hds.model.StorageArray)11 ClientResponse (com.sun.jersey.api.client.ClientResponse)11 IOException (java.io.IOException)11 InputStream (java.io.InputStream)11 JavaResult (org.milyn.payload.JavaResult)11 ExportMask (com.emc.storageos.db.client.model.ExportMask)10 HDSException (com.emc.storageos.hds.HDSException)9 StringSetMap (com.emc.storageos.db.client.model.StringSetMap)8 Path (com.emc.storageos.hds.model.Path)7 HashSet (java.util.HashSet)7 ServiceError (com.emc.storageos.svcs.errorhandling.model.ServiceError)6 StoragePort (com.emc.storageos.db.client.model.StoragePort)5 Add (com.emc.storageos.hds.model.Add)5