Search in sources :

Example 16 with HostStorageDomain

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

the class HDSExportMaskVolumesValidator method validate.

@Override
public boolean validate() throws Exception {
    log.info("Initiating volumes 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> discoveredInitiators = new HashSet<>();
                HostStorageDomain hsd = exportManager.getHostStorageDomain(systemObjectID, hsdObjectIdFromDb);
                if (null == hsd) {
                    continue;
                }
                maskName = (null == hsd.getName()) ? hsd.getNickname() : hsd.getName();
                // Get initiators from storage system
                discoveredInitiators.addAll(HDSUtils.getInitiatorsFromHSD(hsd));
                log.info("Initiators {} discovered from array for the HSD {}", discoveredInitiators, maskName);
                Set<String> additionalInitiatorsOnArray = Sets.difference(discoveredInitiators, initiatorsInExportMask);
                if (!CollectionUtils.isEmpty(additionalInitiatorsOnArray)) {
                    getValidatorLogger().logDiff(String.format("%s - %s", id, maskName), "initiators", ValidatorLogger.NO_MATCHING_ENTRY, Joiner.on("\t").join(additionalInitiatorsOnArray));
                }
            }
            checkForErrors();
        }
    } catch (Exception ex) {
        log.error("Unexpected exception validating ExportMask volumes: " + ex.getMessage(), ex);
        if (getValidatorConfig().isValidationEnabled()) {
            throw DeviceControllerException.exceptions.unexpectedCondition("Unexpected exception validating ExportMask volumes: " + 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)

Example 17 with HostStorageDomain

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

the class HDSApiExportManager method addISCSIInitatorsToHostStorageDomain.

/**
 * Add WWN to the HostStorageDomain means enable LUN security by adding WWN.
 *
 * @param systemId
 * @param hsdId
 * @param scsiNameList
 * @param model
 * @return
 * @throws Exception
 */
public HostStorageDomain addISCSIInitatorsToHostStorageDomain(String systemId, String hsdId, List<String> scsiNameList, String model) throws Exception {
    InputStream responseStream = null;
    HostStorageDomain hsd = null;
    try {
        String addISCSINamesToHSDQuery = constructISCSIQuery(systemId, hsdId, scsiNameList, model);
        log.info("Query to add SCSI Initiators to HostStorageDomain: {}", addISCSINamesToHSDQuery);
        URI endpointURI = hdsApiClient.getBaseURI();
        ClientResponse response = hdsApiClient.post(endpointURI, addISCSINamesToHSDQuery);
        if (HttpStatus.SC_OK == response.getStatus()) {
            responseStream = response.getEntityInputStream();
            JavaResult javaResult = SmooksUtil.getParsedXMLJavaResult(responseStream, HDSConstants.SMOOKS_CONFIG_FILE);
            verifyErrorPayload(javaResult);
            hsd = javaResult.getBean(HostStorageDomain.class);
            if (null == hsd) {
                throw HDSException.exceptions.notAbleToAddInitiatorToHostStorageDomain("iSCSI", hsdId, systemId);
            }
        } else {
            throw HDSException.exceptions.invalidResponseFromHDS(String.format("Add iSCSI initiator to HostStorageDomain failed 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 hsd;
}
Also used : ClientResponse(com.sun.jersey.api.client.ClientResponse) HostStorageDomain(com.emc.storageos.hds.model.HostStorageDomain) InputStream(java.io.InputStream) IOException(java.io.IOException) URI(java.net.URI) JavaResult(org.milyn.payload.JavaResult)

Example 18 with HostStorageDomain

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

the class HDSApiExportManager method constructISCSIQuery.

/**
 * 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 constructISCSIQuery(String systemId, String hsdId, List<String> scsiNameList, String model) {
    Map<String, Object> attributeMap = new HashMap<String, Object>();
    StorageArray array = new StorageArray(systemId);
    Add addOp = new Add(HDSConstants.ISCSI_NAME_FOR_HSD_TARGET);
    attributeMap.put(HDSConstants.STORAGEARRAY, array);
    attributeMap.put(HDSConstants.ADD, addOp);
    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 addISCSINamesToHSDQuery = InputXMLGenerationClient.getInputXMLString(HDSConstants.ADD_ISCSI_NAME_TO_HSD_OP, attributeMap, HDSConstants.HITACHI_INPUT_XML_CONTEXT_FILE, HDSConstants.HITACHI_SMOOKS_CONFIG_FILE);
    return addISCSINamesToHSDQuery;
}
Also used : Add(com.emc.storageos.hds.model.Add) 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 19 with HostStorageDomain

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

the class HDSApiExportManager method addHostStorageDomain.

/**
 * Add new HostStorageDomain.
 *
 * @param systemId
 * @param targetPortID
 * @param hsdNickName
 * @param hostMode.
 * @param hostModeOption
 * @param model
 * @return
 * @throws Exception
 */
public HostStorageDomain addHostStorageDomain(String systemId, String targetPortID, String domainType, String hsdName, String hsdNickName, String hostMode, String hostModeOption, String model) throws Exception {
    InputStream responseStream = null;
    HostStorageDomain hsd = 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);
        HostStorageDomain inputHsd = new HostStorageDomain(targetPortID, hsdName, domainType, hsdNickName);
        inputHsd.setHostMode(hostMode);
        inputHsd.setHostModeOption(hostModeOption);
        attributeMap.put(HDSConstants.HOST_STORAGE_DOMAIN, inputHsd);
        String addHSDToSystemQuery = InputXMLGenerationClient.getInputXMLString(HDSConstants.ADD_HSD_TO_SYSTEM_OP, attributeMap, HDSConstants.HITACHI_INPUT_XML_CONTEXT_FILE, HDSConstants.HITACHI_SMOOKS_CONFIG_FILE);
        log.info("Query to create HostStorageDomain: {}", 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);
            hsd = javaResult.getBean(HostStorageDomain.class);
            if (null == hsd) {
                throw HDSException.exceptions.notAbleToAddHSD(systemId);
            }
        } else {
            throw HDSException.exceptions.invalidResponseFromHDS(String.format("Not able to add 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 hsd;
}
Also used : Add(com.emc.storageos.hds.model.Add) ClientResponse(com.sun.jersey.api.client.ClientResponse) HostStorageDomain(com.emc.storageos.hds.model.HostStorageDomain) HashMap(java.util.HashMap) InputStream(java.io.InputStream) IOException(java.io.IOException) URI(java.net.URI) JavaResult(org.milyn.payload.JavaResult) StorageArray(com.emc.storageos.hds.model.StorageArray)

Example 20 with HostStorageDomain

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

the class HDSApiExportManager method addWWNToHostStorageDomain.

/**
 * Add WWN to the HostStorageDomain means enable LUN security by adding WWN.
 *
 * @param systemId
 * @param hsdId
 * @param wwnList
 * @param model
 * @return
 * @throws Exception
 */
public HostStorageDomain addWWNToHostStorageDomain(String systemId, String hsdId, List<String> wwnList, String model) throws Exception {
    InputStream responseStream = null;
    HostStorageDomain hsd = null;
    try {
        String addWWNToHSDQuery = constructWWNQuery(systemId, hsdId, wwnList, model);
        log.info("Query to add FC initiators to HostStorageDomain: {}", addWWNToHSDQuery);
        URI endpointURI = hdsApiClient.getBaseURI();
        ClientResponse response = hdsApiClient.post(endpointURI, addWWNToHSDQuery);
        if (HttpStatus.SC_OK == response.getStatus()) {
            responseStream = response.getEntityInputStream();
            JavaResult javaResult = SmooksUtil.getParsedXMLJavaResult(responseStream, HDSConstants.SMOOKS_CONFIG_FILE);
            verifyErrorPayload(javaResult);
            hsd = javaResult.getBean(HostStorageDomain.class);
            if (null == hsd) {
                throw HDSException.exceptions.notAbleToAddInitiatorToHostStorageDomain("FC", hsdId, systemId);
            }
        } else {
            throw HDSException.exceptions.invalidResponseFromHDS(String.format("Add initiator to HostStorageDomain failed 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 hsd;
}
Also used : ClientResponse(com.sun.jersey.api.client.ClientResponse) HostStorageDomain(com.emc.storageos.hds.model.HostStorageDomain) InputStream(java.io.InputStream) IOException(java.io.IOException) URI(java.net.URI) JavaResult(org.milyn.payload.JavaResult)

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