Search in sources :

Example 21 with NetworkDeviceControllerException

use of com.emc.storageos.networkcontroller.exceptions.NetworkDeviceControllerException in project coprhd-controller by CoprHD.

the class MDSDialog method zonesetActivate.

/**
 * zoneset activate name {zonesetName} vsan {vsanId}
 * no zoneset activate name {zonesetName} vsan {vsanId}
 *
 * @param zonesetName
 * @param vsanId
 * @param no (boolean) if true, issues "no" form of this command
 * @throws NetworkDeviceControllerException
 */
public void zonesetActivate(String zonesetName, Integer vsanId, boolean no) throws NetworkDeviceControllerException {
    if (!inConfigMode) {
        throw NetworkDeviceControllerException.exceptions.mdsDeviceNotInConfigMode();
    }
    if (lastPrompt != SSHPrompt.MDS_CONFIG) {
        throw NetworkDeviceControllerException.exceptions.mdsUnexpectedLastPrompt(lastPrompt.toString(), SSHPrompt.MDS_CONFIG.toString());
    }
    // no
    String noString = no ? MDSDialogProperties.getString("MDSDialog.zonesetActivate.no.cmd") : "";
    SSHPrompt[] prompts = { SSHPrompt.MDS_CONFIG, SSHPrompt.MDS_CONTINUE_QUERY };
    StringBuilder buf = new StringBuilder();
    boolean retryNeeded = true;
    for (int retryCount = 0; retryCount < sessionLockRetryMax && retryNeeded; retryCount++) {
        String payload = MessageFormat.format(MDSDialogProperties.getString("MDSDialog.zonesetActivate.cmd"), zonesetName, vsanId.toString(), // {2}zoneset activate name {0} vsan {1}\n
        noString);
        lastPrompt = sendWaitFor(payload, defaultTimeout, prompts, buf);
        // error, throw exception. Otherwise check for enhance zone session
        if (buf.toString().indexOf(MDSDialogProperties.getString("MDSDialog.zonesetActivate.no.zone.members")) >= 0) {
            throw new NetworkDeviceControllerException("Activate zoneset/vsan: " + zonesetName + "/" + vsanId + " failed.  One or more zone do not have members");
        } else {
            // check for user input
            if (lastPrompt == SSHPrompt.MDS_CONTINUE_QUERY) {
                // y\n
                payload = MDSDialogProperties.getString("MDSDialog.zonesetActivate.continue.y.cmd");
                SSHPrompt[] prompts2 = { SSHPrompt.MDS_CONFIG };
                buf = new StringBuilder();
                lastPrompt = sendWaitFor(payload, defaultTimeout, prompts2, buf);
            }
            String[] lines = getLines(buf);
            retryNeeded = checkForEnhancedZoneSession(lines, retryCount);
        }
    }
}
Also used : NetworkDeviceControllerException(com.emc.storageos.networkcontroller.exceptions.NetworkDeviceControllerException) SSHPrompt(com.emc.storageos.networkcontroller.SSHPrompt) FCEndpoint(com.emc.storageos.db.client.model.FCEndpoint)

Example 22 with NetworkDeviceControllerException

use of com.emc.storageos.networkcontroller.exceptions.NetworkDeviceControllerException in project coprhd-controller by CoprHD.

the class MDSDialog method zoneAddRemoveMember.

/**
 * Add zone "member device-alias {alias}" if useAlias is set to true, other
 * uses "member pwwn {pwwn}"
 *
 * @param address
 * @param useAlias
 * @throws NetworkDeviceControllerException
 */
private void zoneAddRemoveMember(String address, boolean useAlias, boolean remove) throws NetworkDeviceControllerException {
    String mdsCommand = "";
    if (!inConfigMode) {
        throw NetworkDeviceControllerException.exceptions.mdsDeviceNotInConfigMode();
    }
    if (lastPrompt != SSHPrompt.MDS_CONFIG_ZONE) {
        throw NetworkDeviceControllerException.exceptions.mdsUnexpectedLastPrompt(lastPrompt.toString(), SSHPrompt.MDS_CONFIG_ZONE.toString());
    }
    if (useAlias) {
        // add memeber via device-alias
        mdsCommand = MDSDialogProperties.getString("MDSDialog.zoneMemberAlias.cmd");
    } else {
        // add member via pwwn
        if (!address.matches(wwnRegex)) {
            String message = "port wwn " + address + " is not formatted correctly";
            throw NetworkDeviceControllerException.exceptions.mdsUnexpectedDeviceState(message);
        }
        mdsCommand = MDSDialogProperties.getString("MDSDialog.zoneMemberPwwn.cmd");
    }
    if (remove) {
        mdsCommand = MDSDialogProperties.getString("MDSDialog.zonesetActivate.no.cmd") + " " + mdsCommand;
    }
    SSHPrompt[] prompts = { SSHPrompt.MDS_CONFIG_ZONE };
    StringBuilder buf = new StringBuilder();
    boolean retryNeeded = true;
    for (int retryCount = 0; retryCount < sessionLockRetryMax && retryNeeded; retryCount++) {
        // =member pwwn {0}\n
        String payload = MessageFormat.format(mdsCommand, address);
        lastPrompt = sendWaitFor(payload, defaultTimeout, prompts, buf);
        String[] lines = getLines(buf);
        for (String line : lines) {
            // add mode - throw exception if alias is not found
            if (!remove) {
                if (line.indexOf(MDSDialogProperties.getString("MDSDialog.not.present")) >= 0) {
                    throw new NetworkDeviceControllerException(line + ": " + address);
                }
            }
        }
        retryNeeded = checkForEnhancedZoneSession(lines, retryCount);
    }
}
Also used : NetworkDeviceControllerException(com.emc.storageos.networkcontroller.exceptions.NetworkDeviceControllerException) SSHPrompt(com.emc.storageos.networkcontroller.SSHPrompt) FCEndpoint(com.emc.storageos.db.client.model.FCEndpoint)

Example 23 with NetworkDeviceControllerException

use of com.emc.storageos.networkcontroller.exceptions.NetworkDeviceControllerException in project coprhd-controller by CoprHD.

the class MDSDialog method waitForIvrZonesetActivate.

/**
 * Wait for activation finish processing
 *
 * @throws NetworkDeviceControllerException
 */
public void waitForIvrZonesetActivate() throws NetworkDeviceControllerException {
    _log.info(MessageFormat.format("Host: {0}, Port: {1} - BEGIN waitForIvrZonesetActivate", new Object[] { getSession().getSession().getHost(), getSession().getSession().getPort() }));
    _log.info("Waiting for ivr zoneset to activate");
    SSHPrompt[] prompts = { SSHPrompt.MDS_POUND, SSHPrompt.MDS_GREATER_THAN, SSHPrompt.MDS_CONFIG, SSHPrompt.MDS_CONFIG_IVR_ZONE, SSHPrompt.MDS_CONFIG_IVR_ZONESET };
    StringBuilder buf = new StringBuilder();
    // show zone status vsan {0}\n
    String payload = MDSDialogProperties.getString("MDSDialog.ivr.show.zoneset.status.cmd");
    String[] regex = { // ^State:\\s+activating*
    MDSDialogProperties.getString("MDSDialog.ivr.waitForZoneset.activate.inprogress.match"), // ^State:\\s+activation success*
    MDSDialogProperties.getString("MDSDialog.ivr.waitForZoneset.activate.success.match") };
    String[] groups = new String[2];
    boolean completed = false;
    for (int i = 0; i < defaultTimeout && completed == false; i += 1000) {
        try {
            // sleep one second
            Thread.sleep(1000);
        } catch (InterruptedException ex) {
            _log.warn(ex.getLocalizedMessage());
        }
        lastPrompt = sendWaitFor(payload, defaultTimeout, prompts, buf);
        String[] lines = getLines(buf);
        for (String line : lines) {
            int index = match(line, regex, groups);
            switch(index) {
                case 0:
                    completed = false;
                    break;
                case 1:
                    completed = true;
                    break;
                case 2:
                    throw new NetworkDeviceControllerException("ivr zoneset activate Commit failed: " + line);
            }
            if (completed) {
                break;
            }
        }
    }
    _log.info(MessageFormat.format("Host: {0}, Port: {1} -DONE waitForIvrZonesetActivate", new Object[] { getSession().getSession().getHost(), getSession().getSession().getPort() }));
}
Also used : NetworkDeviceControllerException(com.emc.storageos.networkcontroller.exceptions.NetworkDeviceControllerException) SSHPrompt(com.emc.storageos.networkcontroller.SSHPrompt) FCEndpoint(com.emc.storageos.db.client.model.FCEndpoint)

Example 24 with NetworkDeviceControllerException

use of com.emc.storageos.networkcontroller.exceptions.NetworkDeviceControllerException in project coprhd-controller by CoprHD.

the class MDSDialog method ivrZoneName.

/**
 * Configure ivr zone or zone set depended on isZoneset flag.
 *
 * @param isZoneset indicate to config ivr zoneset, otherwise ivr zone
 * @param zoneName
 * @param isActivate make zoneset active
 * @param isRemove remove zoneset
 * @throws NetworkDeviceControllerException
 */
private void ivrZoneName(boolean isZoneset, String zoneName, boolean isActivate, boolean isRemove) throws NetworkDeviceControllerException {
    _log.info(MessageFormat.format("Host: {0}, Port: {1} - BEGIN Configure {2}: {3} - Remove {4}", new Object[] { getSession().getSession().getHost(), getSession().getSession().getPort(), isZoneset ? "zoneset" : "zone", zoneName, isRemove }));
    if (!inConfigMode) {
        throw NetworkDeviceControllerException.exceptions.mdsDeviceNotInConfigMode();
    }
    SSHPrompt[] promptsToCheck = { SSHPrompt.MDS_CONFIG, SSHPrompt.MDS_CONFIG_IVR_ZONE, SSHPrompt.MDS_CONFIG_IVR_ZONESET };
    if (!Arrays.asList(promptsToCheck).contains(lastPrompt)) {
        String message = Arrays.asList(promptsToCheck).toString();
        throw NetworkDeviceControllerException.exceptions.mdsUnexpectedLastPrompt(lastPrompt.toString(), message);
    }
    // cannot be activate and remove at the same time
    if (isActivate && isRemove) {
        String message = "cannot be activate and remove at the same time";
        throw NetworkDeviceControllerException.exceptions.mdsUnexpectedDeviceState(message);
    }
    String ivrZoneNameResourceKey = "MDSDialog.ivr.zoneName.cmd";
    if (isZoneset) {
        // only zoneset can be activate
        ivrZoneNameResourceKey = isActivate ? "MDSDialog.ivr.zonesetName.activate.cmd" : "MDSDialog.ivr.zonesetName.cmd";
    }
    SSHPrompt[] prompts = { isZoneset ? SSHPrompt.MDS_CONFIG_IVR_ZONESET : SSHPrompt.MDS_CONFIG_IVR_ZONE, SSHPrompt.MDS_CONFIG };
    // no
    String noString = isRemove ? MDSDialogProperties.getString("MDSDialog.zoneNameVsan.no.cmd") : "";
    StringBuilder buf = new StringBuilder();
    String payload = MessageFormat.format(noString + MDSDialogProperties.getString(ivrZoneNameResourceKey), zoneName);
    boolean retryNeeded = true;
    boolean error = false;
    String errorMessage = MDSDialogProperties.getString("MDSDialog.ivr.waitForZoneset.activate.error.atLeast2Members");
    for (int retryCount = 0; retryCount < sessionLockRetryMax && retryNeeded; retryCount++) {
        lastPrompt = sendWaitFor(payload, defaultTimeout, prompts, buf);
        String[] lines = getLines(buf);
        retryNeeded = checkForIvrZoneSession(lines, retryCount);
        if (isActivate && isZoneset) {
            for (String line : lines) {
                error = line.indexOf(errorMessage) >= 0;
                if (error) {
                    break;
                }
            }
        }
    }
    // verify for appropriate prompt
    if (isZoneset) {
        SSHPrompt[] morePromptsToCheck = { SSHPrompt.MDS_CONFIG_IVR_ZONESET, SSHPrompt.MDS_CONFIG };
        if (!Arrays.asList(morePromptsToCheck).contains(lastPrompt)) {
            String message = Arrays.asList(morePromptsToCheck).toString();
            throw NetworkDeviceControllerException.exceptions.mdsUnexpectedLastPrompt(lastPrompt.toString(), message);
        }
    } else {
        SSHPrompt[] morePromptsToCheck = { SSHPrompt.MDS_CONFIG_IVR_ZONE, SSHPrompt.MDS_CONFIG };
        if (!Arrays.asList(morePromptsToCheck).contains(lastPrompt)) {
            String message = Arrays.asList(morePromptsToCheck).toString();
            throw NetworkDeviceControllerException.exceptions.mdsUnexpectedLastPrompt(lastPrompt.toString(), message);
        }
    }
    if (error) {
        throw new NetworkDeviceControllerException(errorMessage + ": " + zoneName);
    }
    _log.info(MessageFormat.format("Host: {0}, Port: {1} - END Configure {2}: {3} - Remove {4}", new Object[] { getSession().getSession().getHost(), getSession().getSession().getPort(), isZoneset ? "zoneset" : "zone", zoneName, isRemove }));
}
Also used : NetworkDeviceControllerException(com.emc.storageos.networkcontroller.exceptions.NetworkDeviceControllerException) SSHPrompt(com.emc.storageos.networkcontroller.SSHPrompt) FCEndpoint(com.emc.storageos.db.client.model.FCEndpoint)

Example 25 with NetworkDeviceControllerException

use of com.emc.storageos.networkcontroller.exceptions.NetworkDeviceControllerException in project coprhd-controller by CoprHD.

the class MDSDialog method waitForZoneCommit.

/**
 * Waits for a zone commit to complete. Checks for in-progress and failed status.
 *
 * @param vsanId
 * @throws NetworkDeviceControllerException
 */
public void waitForZoneCommit(Integer vsanId) throws NetworkDeviceControllerException {
    _log.info(MessageFormat.format("Host: {0}, Port: {1} - BEGIN waitForZoneCommit", new Object[] { getSession().getSession().getHost(), getSession().getSession().getPort() }));
    SSHPrompt[] prompts = { SSHPrompt.MDS_POUND, SSHPrompt.MDS_CONFIG };
    StringBuilder buf = new StringBuilder();
    String payload = MessageFormat.format(MDSDialogProperties.getString("MDSDialog.waitForZoneCommit.showzonestatusvsan.cmd"), // show zone status vsan {0}\n
    vsanId.toString());
    String[] regex = { // ^Status:\\s+Commit in progress.*
    MDSDialogProperties.getString("MDSDialog.waitForZoneCommit.inprogress.match"), // ^Status:\\s+Commit complete.*
    MDSDialogProperties.getString("MDSDialog.waitForZoneCommit.complete.match"), // ^Status:\\s+Operation failed.*
    MDSDialogProperties.getString("MDSDialog.waitForZoneCommit.failed.match") };
    String[] groups = new String[2];
    /*
         * compute retry attempts based on the configured timeout.
         * will retry in every SLEEP_TIME_PER_RETRY until exceeded the timeout value
         * Add one more attempt to ensure timeout value is reached
         */
    int retryAttempts = defaultTimeout / MDSDialogProperties.SLEEP_TIME_PER_RETRY + 1;
    boolean completed = false;
    for (int retrys = 0; !completed && retrys < retryAttempts; retrys++) {
        try {
            Thread.sleep(MDSDialogProperties.SLEEP_TIME_PER_RETRY);
        } catch (InterruptedException ex) {
            _log.warn(ex.getLocalizedMessage());
        }
        lastPrompt = sendWaitFor(payload, defaultTimeout, prompts, buf);
        String[] lines = getLines(buf);
        for (String line : lines) {
            int index = match(line, regex, groups);
            switch(index) {
                case 0:
                    completed = false;
                    break;
                case 1:
                    completed = true;
                    break;
                case 2:
                    throw new NetworkDeviceControllerException("Zone Commit failed: " + line);
            }
        }
    }
    _log.info(MessageFormat.format("Host: {0}, Port: {1} - END waitForZoneCommit", new Object[] { getSession().getSession().getHost(), getSession().getSession().getPort() }));
}
Also used : NetworkDeviceControllerException(com.emc.storageos.networkcontroller.exceptions.NetworkDeviceControllerException) SSHPrompt(com.emc.storageos.networkcontroller.SSHPrompt) FCEndpoint(com.emc.storageos.db.client.model.FCEndpoint)

Aggregations

NetworkDeviceControllerException (com.emc.storageos.networkcontroller.exceptions.NetworkDeviceControllerException)26 HashMap (java.util.HashMap)12 FCEndpoint (com.emc.storageos.db.client.model.FCEndpoint)10 BiosCommandResult (com.emc.storageos.volumecontroller.impl.BiosCommandResult)10 SSHPrompt (com.emc.storageos.networkcontroller.SSHPrompt)7 ControllerException (com.emc.storageos.volumecontroller.ControllerException)7 ArrayList (java.util.ArrayList)7 DeviceControllerException (com.emc.storageos.exceptions.DeviceControllerException)5 CIMInstance (javax.cim.CIMInstance)5 CIMObjectPath (javax.cim.CIMObjectPath)5 WBEMException (javax.wbem.WBEMException)5 WBEMClient (javax.wbem.client.WBEMClient)5 Zone (com.emc.storageos.networkcontroller.impl.mds.Zone)3 NetworkLite (com.emc.storageos.util.NetworkLite)2 List (java.util.List)2 IntRange (org.apache.commons.lang.math.IntRange)2 ContainmentConstraint (com.emc.storageos.db.client.constraint.ContainmentConstraint)1 URIQueryResultList (com.emc.storageos.db.client.constraint.URIQueryResultList)1 Network (com.emc.storageos.db.client.model.Network)1 NetworkSystem (com.emc.storageos.db.client.model.NetworkSystem)1