Search in sources :

Example 6 with HDSHost

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

the class HDSApiProtectionManager method getReplicationInfoFromSystem.

public Pair<ReplicationInfo, String> getReplicationInfoFromSystem(String sourceNativeId, String targetNativeId) throws Exception {
    log.info("sourceNativeId :{}", sourceNativeId);
    log.info("targetNativeId :{}", targetNativeId);
    List<HDSHost> hostList = getHDSHostList();
    if (hostList != null) {
        for (HDSHost hdsHost : hostList) {
            log.info("HDSHost :{}", hdsHost.toXMLString());
            if (hdsHost != null && hdsHost.getConfigFileList() != null && !hdsHost.getConfigFileList().isEmpty()) {
                for (ConfigFile configFile : hdsHost.getConfigFileList()) {
                    if (configFile != null) {
                        ReplicationGroup replicationGroup = configFile.getReplicationGroup();
                        if (replicationGroup != null && replicationGroup.getReplicationInfoList() != null) {
                            log.info("replicationGroup :{}", replicationGroup.toXMLString());
                            List<ReplicationInfo> replicationInfoList = replicationGroup.getReplicationInfoList();
                            if (replicationInfoList != null) {
                                for (ReplicationInfo replicationInfo : replicationInfoList) {
                                    log.debug("replicationInfo :{}", replicationInfo.toXMLString());
                                    if (sourceNativeId.equals(replicationInfo.getPvolDevNum()) && targetNativeId.equals(replicationInfo.getSvolDevNum())) {
                                        log.info("Found replicationInfo object from system:{}", replicationInfo.toXMLString());
                                        log.info("Host Object Id :{}", hdsHost.getObjectID());
                                        return (new Pair<ReplicationInfo, String>(replicationInfo, hdsHost.getObjectID()));
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }
    // If we are here there is no matching replication info available on pair management server.
    log.error("Unable to find replication info details from device manager for the pvol {} svol {}", sourceNativeId, targetNativeId);
    return null;
}
Also used : HDSHost(com.emc.storageos.hds.model.HDSHost) ConfigFile(com.emc.storageos.hds.model.ConfigFile) ReplicationInfo(com.emc.storageos.hds.model.ReplicationInfo) ReplicationGroup(com.emc.storageos.hds.model.ReplicationGroup)

Example 7 with HDSHost

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

the class HDSApiProtectionManager method createThinImagePair.

/**
 * Creates ThinImage pair for HDS Snapshot
 *
 * @param snapshotGroupObjId
 * @param hostObjId
 * @param sourNativeId
 * @param snapNativeId
 * @param thinImagePoolId
 * @return
 * @throws Exception
 */
public boolean createThinImagePair(String snapshotGroupObjId, String hostObjId, String sourNativeId, String snapNativeId, String thinImagePoolId, String model) throws Exception {
    log.info("Thin Image pair creation started");
    boolean status = false;
    InputStream responseStream = null;
    String syncTaskMessageId = null;
    try {
        log.info("snapshotGroupObjId {} ", snapshotGroupObjId);
        Map<String, Object> attributeMap = new HashMap<String, Object>();
        Add addOp = new Add(HDSConstants.REPLICATION);
        addOp.setOption(HDSConstants.INBAND2);
        HDSHost host = new HDSHost();
        host.setObjectID(hostObjId);
        SnapshotGroup snapshotGroup = new SnapshotGroup();
        snapshotGroup.setObjectID(snapshotGroupObjId);
        snapshotGroup.setReplicationFunction(HDSConstants.THIN_IMAGE);
        ReplicationInfo replicationInfo = new ReplicationInfo();
        replicationInfo.setPvolDevNum(sourNativeId);
        replicationInfo.setSvolDevNum(snapNativeId);
        replicationInfo.setPvolPoolID(thinImagePoolId);
        attributeMap.put(HDSConstants.ADD, addOp);
        attributeMap.put(HDSConstants.MODEL, model);
        attributeMap.put(HDSConstants.HOST, host);
        attributeMap.put(HDSConstants.SNAPSHOTGROUP, snapshotGroup);
        attributeMap.put(HDSConstants.REPLICATION_INFO, replicationInfo);
        String createThinImagePairInputXML = InputXMLGenerationClient.getInputXMLString(HDSConstants.CREATE_THIN_IMAGE_PAIR_OP, attributeMap, HDSConstants.HITACHI_INPUT_XML_CONTEXT_FILE, HDSConstants.HITACHI_SMOOKS_CONFIG_FILE);
        log.info("Query to create thin image pair : {}", createThinImagePairInputXML);
        URI endpointURI = hdsApiClient.getBaseURI();
        ClientResponse response = hdsApiClient.post(endpointURI, createThinImagePairInputXML);
        if (HttpStatus.SC_OK == response.getStatus()) {
            responseStream = response.getEntityInputStream();
            JavaResult result = SmooksUtil.getParsedXMLJavaResult(responseStream, HDSConstants.HITACHI_SMOOKS_THINIMAGE_CONFIG_FILE);
            EchoCommand command = result.getBean(EchoCommand.class);
            if (HDSConstants.COMPLETED_STR.equalsIgnoreCase(command.getStatus())) {
                log.info("ThinImage Pair has been created successfully");
                status = true;
                SnapshotGroup snapshotGrpResponse = result.getBean(SnapshotGroup.class);
                if (null == snapshotGrpResponse) {
                    throw HDSException.exceptions.notAbleToCreateThinImagePair();
                }
            } else if (HDSConstants.PROCESSING_STR.equalsIgnoreCase(command.getStatus())) {
                syncTaskMessageId = command.getMessageID();
            } else if (HDSConstants.FAILED_STR.equalsIgnoreCase(command.getStatus())) {
                Error error = result.getBean(Error.class);
                log.error("Thin Image pair creation failed status messageID: {}", command.getMessageID());
                log.error("Thin Image pair creation failed with error code: {} with message: {}", error.getCode(), error.getDescription());
                throw HDSException.exceptions.notAbleToCreateThinImagePairError(error.getCode(), error.getDescription());
            }
        } else {
            log.error("Thin Image pair creation failed with invalid response code {}", response.getStatus());
            throw HDSException.exceptions.invalidResponseFromHDS(String.format("Thin Image pair creation failed due to invalid response %1$s from server", response.getStatus()));
        }
    } finally {
        if (null != responseStream) {
            try {
                responseStream.close();
            } catch (IOException e) {
                log.warn("Exception occurred while close Thin Image Pair creation response stream");
            }
        }
    }
    log.info("Thin Image pair creation completed");
    return status;
}
Also used : Add(com.emc.storageos.hds.model.Add) ClientResponse(com.sun.jersey.api.client.ClientResponse) HDSHost(com.emc.storageos.hds.model.HDSHost) HashMap(java.util.HashMap) InputStream(java.io.InputStream) Error(com.emc.storageos.hds.model.Error) IOException(java.io.IOException) URI(java.net.URI) SnapshotGroup(com.emc.storageos.hds.model.SnapshotGroup) ReplicationInfo(com.emc.storageos.hds.model.ReplicationInfo) JavaResult(org.milyn.payload.JavaResult) EchoCommand(com.emc.storageos.hds.model.EchoCommand)

Example 8 with HDSHost

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

the class HDSApiProtectionManager method refreshPairManagementServer.

public void refreshPairManagementServer(String pairMgmtServerHostObjId) throws Exception {
    InputStream responseStream = null;
    try {
        if (pairMgmtServerHostObjId != null) {
            log.info("Refreshing Pair Mgmt Server started");
            Map<String, Object> attributeMap = new HashMap<String, Object>();
            Add addOp = new Add(HDSConstants.HOST_REFRESH);
            HDSHost host = new HDSHost();
            host.setObjectID(pairMgmtServerHostObjId);
            attributeMap.put(HDSConstants.ADD, addOp);
            attributeMap.put(HDSConstants.HOST, host);
            String refreshHostQuery = InputXMLGenerationClient.getInputXMLString(HDSConstants.REFRESH_HOST_OP, attributeMap, HDSConstants.HITACHI_INPUT_XML_CONTEXT_FILE, HDSConstants.HITACHI_SMOOKS_CONFIG_FILE);
            log.info("Query to refresh pair mgmt server: {}", refreshHostQuery);
            URI endpointURI = hdsApiClient.getBaseURI();
            ClientResponse response = hdsApiClient.post(endpointURI, refreshHostQuery);
            if (HttpStatus.SC_OK == response.getStatus()) {
                responseStream = response.getEntityInputStream();
                JavaResult javaResult = SmooksUtil.getParsedXMLJavaResult(responseStream, HDSConstants.HITACHI_SMOOKS_THINIMAGE_CONFIG_FILE);
                verifyErrorPayload(javaResult);
                log.info("Successfully refreshed pair mgmt server");
            } else {
                throw HDSException.exceptions.invalidResponseFromHDS(String.format("Not able to refresh pair mgmt server due to invalid response %1$s from server", response.getStatus()));
            }
        } else {
            log.info("Pair Mgmt Server Object id is null");
        }
    } finally {
        if (null != responseStream) {
            try {
                responseStream.close();
            } catch (IOException e) {
                log.warn("IOException occurred while closing the response stream");
            }
        }
    }
}
Also used : Add(com.emc.storageos.hds.model.Add) ClientResponse(com.sun.jersey.api.client.ClientResponse) HDSHost(com.emc.storageos.hds.model.HDSHost) HashMap(java.util.HashMap) InputStream(java.io.InputStream) IOException(java.io.IOException) URI(java.net.URI) JavaResult(org.milyn.payload.JavaResult)

Example 9 with HDSHost

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

the class HDSExportOperations method registerHostsWithInitiators.

/**
 * Registers all the hosts and its initiators with Device Manager.
 *
 * @param initiatorList
 * @param hdsApiClient
 * @param exportMgr
 * @return
 * @throws Exception
 */
private void registerHostsWithInitiators(List<Initiator> initiatorList, HDSApiClient hdsApiClient) throws Exception {
    Map<HDSHost, List<String>> fcHostsToRegister = new HashMap<HDSHost, List<String>>();
    Map<HDSHost, List<String>> iSCSIHostsToRegister = new HashMap<HDSHost, List<String>>();
    HDSApiExportManager exportMgr = hdsApiClient.getHDSApiExportManager();
    if (null != initiatorList) {
        for (Initiator initiator : initiatorList) {
            if (null != initiator.getHost()) {
                Host host = dbClient.queryObject(Host.class, initiator.getHost());
                if (null != host) {
                    // Get host type and OS type of the host
                    Pair<String, String> hostTypeAndOsType = getHostTypeAndOSTypeToRegisterHost(host);
                    HDSHost hdshost = new HDSHost(host.getHostName());
                    hdshost.setHostType(hostTypeAndOsType.first);
                    hdshost.setOsType(hostTypeAndOsType.second);
                    String portWWN = initiator.getInitiatorPort().replace(HDSConstants.COLON, HDSConstants.DOT_OPERATOR);
                    if (initiator.getProtocol().equals(HostInterface.Protocol.FC.name())) {
                        if (!fcHostsToRegister.containsKey(hdshost)) {
                            List<String> initiatorsList = new ArrayList<String>();
                            initiatorsList.add(portWWN);
                            fcHostsToRegister.put(hdshost, initiatorsList);
                        } else {
                            fcHostsToRegister.get(hdshost).add(portWWN);
                        }
                    } else if (initiator.getProtocol().equals(HostInterface.Protocol.iSCSI.name())) {
                        if (!iSCSIHostsToRegister.containsKey(hdshost)) {
                            List<String> initiatorsList = new ArrayList<String>();
                            initiatorsList.add(portWWN);
                            iSCSIHostsToRegister.put(hdshost, initiatorsList);
                        } else {
                            iSCSIHostsToRegister.get(hdshost).add(portWWN);
                        }
                    }
                }
            }
        }
    }
    if (!fcHostsToRegister.isEmpty()) {
        for (Map.Entry<HDSHost, List<String>> entry : fcHostsToRegister.entrySet()) {
            HDSHost hdshost = entry.getKey();
            // Try registering the host, if host already exists, we will get an exception.
            // Validating host and its portwwns is costly hence directly adding the host to Device Manager.
            HDSHost registeredHost = exportMgr.registerHost(hdshost, entry.getValue(), HDSConstants.FC);
            if (null != registeredHost) {
                log.info("Host: {} added successfully.", registeredHost.getName());
            }
        }
    }
    if (!iSCSIHostsToRegister.isEmpty()) {
        for (Map.Entry<HDSHost, List<String>> entry : iSCSIHostsToRegister.entrySet()) {
            HDSHost hdshost = entry.getKey();
            // Try registering the host, if host already exists, we will get an exception.
            // Validating host and its portwwns is costly hence directly adding the host to Device Manager.
            HDSHost registeredHost = exportMgr.registerHost(hdshost, entry.getValue(), HDSConstants.ISCSI);
            if (null != registeredHost) {
                log.info("Host: {} added successfully.", registeredHost.getName());
            }
        }
    }
}
Also used : HDSHost(com.emc.storageos.hds.model.HDSHost) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) HDSHost(com.emc.storageos.hds.model.HDSHost) Host(com.emc.storageos.db.client.model.Host) HDSApiExportManager(com.emc.storageos.hds.api.HDSApiExportManager) Initiator(com.emc.storageos.db.client.model.Initiator) List(java.util.List) ArrayList(java.util.ArrayList) URIQueryResultList(com.emc.storageos.db.client.constraint.URIQueryResultList) Map(java.util.Map) HashMap(java.util.HashMap) StringSetMap(com.emc.storageos.db.client.model.StringSetMap)

Example 10 with HDSHost

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

the class HDSApiProtectionManager method getReplicationGroupObjectId.

/**
 * Returns ViPR-Replication-Group objectID collected from Device manager to create ShadowImage pair on
 * Hitachi StorageSystem.
 *
 * @return replicationGroup's objectID
 * @throws Exception
 */
public String getReplicationGroupObjectId() throws Exception {
    List<HDSHost> hostList = getHDSHostList();
    String replicationGroupObjectId = null;
    HDSHost pairMgmtServer = null;
    if (hostList != null) {
        outerloop: for (HDSHost hdsHost : hostList) {
            log.info("HDSHost :{}", hdsHost.toXMLString());
            if (hdsHost != null && hdsHost.getConfigFileList() != null && !hdsHost.getConfigFileList().isEmpty()) {
                for (ConfigFile configFile : hdsHost.getConfigFileList()) {
                    if (configFile != null) {
                        ReplicationGroup replicationGroup = configFile.getReplicationGroup();
                        if (replicationGroup != null && HDSConstants.VIPR_REPLICATION_GROUP_NAME.equalsIgnoreCase(replicationGroup.getGroupName())) {
                            pairMgmtServer = hdsHost;
                            log.info("Pair management server {} found", pairMgmtServer.getName());
                            replicationGroupObjectId = replicationGroup.getObjectID();
                            log.info("ViPR Replication Group {} found", replicationGroup.toXMLString());
                            break outerloop;
                        }
                    }
                }
            }
        }
    }
    return replicationGroupObjectId;
}
Also used : HDSHost(com.emc.storageos.hds.model.HDSHost) ConfigFile(com.emc.storageos.hds.model.ConfigFile) ReplicationGroup(com.emc.storageos.hds.model.ReplicationGroup)

Aggregations

HDSHost (com.emc.storageos.hds.model.HDSHost)15 HashMap (java.util.HashMap)9 ClientResponse (com.sun.jersey.api.client.ClientResponse)8 IOException (java.io.IOException)8 InputStream (java.io.InputStream)8 URI (java.net.URI)8 JavaResult (org.milyn.payload.JavaResult)8 ReplicationInfo (com.emc.storageos.hds.model.ReplicationInfo)7 SnapshotGroup (com.emc.storageos.hds.model.SnapshotGroup)6 BlockSnapshot (com.emc.storageos.db.client.model.BlockSnapshot)3 Volume (com.emc.storageos.db.client.model.Volume)3 DatabaseException (com.emc.storageos.db.exceptions.DatabaseException)3 DeviceControllerException (com.emc.storageos.exceptions.DeviceControllerException)3 HDSException (com.emc.storageos.hds.HDSException)3 HDSApiClient (com.emc.storageos.hds.api.HDSApiClient)3 ConfigFile (com.emc.storageos.hds.model.ConfigFile)3 Get (com.emc.storageos.hds.model.Get)3 ReplicationGroup (com.emc.storageos.hds.model.ReplicationGroup)3 ServiceError (com.emc.storageos.svcs.errorhandling.model.ServiceError)3 Add (com.emc.storageos.hds.model.Add)2