Search in sources :

Example 1 with ZoneWwnAlias

use of com.emc.storageos.networkcontroller.impl.mds.ZoneWwnAlias in project coprhd-controller by CoprHD.

the class NetworkDeviceController method getAliases.

@Override
public List<ZoneWwnAlias> getAliases(URI uri, String fabricId, String fabricWwn) throws ControllerException {
    NetworkSystem device = getNetworkSystemObject(uri);
    // Get the file device reference for the type of file device managed
    // by the controller.
    NetworkSystemDevice networkDevice = getDevice(device.getSystemType());
    if (networkDevice == null) {
        throw NetworkDeviceControllerException.exceptions.getAliasesFailedNull(device.getSystemType());
    }
    try {
        List<ZoneWwnAlias> aliases = networkDevice.getAliases(device, fabricId, fabricWwn);
        return aliases;
    } catch (Exception ex) {
        Date date = new Date();
        throw NetworkDeviceControllerException.errors.getAliasesFailedExc(uri.toString(), date.toString(), ex);
    }
}
Also used : NetworkSystem(com.emc.storageos.db.client.model.NetworkSystem) ZoneWwnAlias(com.emc.storageos.networkcontroller.impl.mds.ZoneWwnAlias) DatabaseException(com.emc.storageos.db.exceptions.DatabaseException) DeviceControllerException(com.emc.storageos.exceptions.DeviceControllerException) ControllerException(com.emc.storageos.volumecontroller.ControllerException) NetworkDeviceControllerException(com.emc.storageos.networkcontroller.exceptions.NetworkDeviceControllerException) Date(java.util.Date)

Example 2 with ZoneWwnAlias

use of com.emc.storageos.networkcontroller.impl.mds.ZoneWwnAlias in project coprhd-controller by CoprHD.

the class BrocadeNetworkSMIS method getAliasFromInstance.

/**
 * Creates an instance of {@link ZoneWwnAlias} from a {@link CIMInstance} after it retrieves
 * the alias member. Note, the alias is expected to have a single member.
 *
 * @param client and instance of WBEMClient
 * @param ins the alias WBEMClient instance
 * @param addMember if true also retrieve the alias WWN member
 * @return an instance of {@link ZoneWwnAlias}
 * @throws WBEMException
 */
private ZoneWwnAlias getAliasFromInstance(WBEMClient client, CIMInstance ins, boolean addMember) throws WBEMException {
    ZoneWwnAlias alias = new ZoneWwnAlias();
    alias.setName(cimStringProperty(ins, _CollectionAlias));
    alias.setCimObjectPath(ins.getObjectPath());
    if (addMember) {
        List<ZoneMember> members = getZoneOrAliasMembers(client, ins.getObjectPath(), true);
        for (ZoneMember member : members) {
            alias.setAddress(EndpointUtility.changeCase(member.getAddress()));
            alias.setCimMemberPath(member.getCimObjectPath());
            // there should only be 1 member
            break;
        }
    }
    return alias;
}
Also used : ZoneMember(com.emc.storageos.networkcontroller.impl.mds.ZoneMember) ZoneWwnAlias(com.emc.storageos.networkcontroller.impl.mds.ZoneWwnAlias)

Example 3 with ZoneWwnAlias

use of com.emc.storageos.networkcontroller.impl.mds.ZoneWwnAlias in project coprhd-controller by CoprHD.

the class BrocadeNetworkSMIS method getAliases.

/**
 * Gets the list of aliases for a given fabric
 * This function uses the associations to improve performance and parses the
 * alias name and member address from the paths:
 * Brocade_ZoneMembershipSettingDataInZoneAlias {
 * ManagedElement =
 * "root/brocade1:Brocade_ZoneAlias.InstanceID=\"NAME=Hala_REST_API_ZONE_12;ACTIVE=false;FABRIC=10000027F858F6C0;CLASSNAME=Brocade_ZoneAlias\""
 * ;
 * SettingData =
 * "root/brocade1:Brocade_ZoneMembershipSettingData.InstanceID=\"NAME=2010101010101010;ZMTYPE=5;ACTIVE=false;FABRIC=10000027F858F6C0;CLASSNAME=Brocade_ZoneMembershipSettingData\""
 * ;
 * };
 *
 * @param client an instance of WBEMClient
 * @param fabricId the name of the fabric
 * @param fabricWwn the WWN of the fabric
 * @throws WBEMException
 */
public List<ZoneWwnAlias> getAliases(WBEMClient client, String fabricId, String fabricWwn) throws WBEMException {
    Map<String, ZoneWwnAlias> aliases = new HashMap<String, ZoneWwnAlias>();
    if (fabricWwn == null) {
        fabricWwn = getFabricWwn(client, fabricId);
    }
    fabricWwn = fabricWwn.replaceAll(":", "");
    CloseableIterator<CIMInstance> it = null;
    try {
        CIMObjectPath path = CimObjectPathCreator.createInstance(_Brocade_ZoneMembershipSettingDataInZoneAlias, _namespace);
        it = client.enumerateInstances(path, false, true, true, null);
        CIMInstance ins = null;
        String aliasPath = null;
        String memberPath = null;
        String wwn = null;
        ZoneWwnAlias alias = null;
        while (it.hasNext()) {
            ins = it.next();
            _log.debug(ins.toString());
            aliasPath = cimStringProperty(ins, _ManagedElement);
            memberPath = cimStringProperty(ins, _SettingData);
            wwn = getPropertyValueFromString(memberPath, SmisConstants.CP_FABRIC);
            if (StringUtils.equalsIgnoreCase(wwn, fabricWwn)) {
                try {
                    alias = new ZoneWwnAlias();
                    alias.setAddress(formatWWN(getPropertyValueFromString(memberPath, SmisConstants.CP_NSNAME)));
                    alias.setName(getPropertyValueFromString(aliasPath, SmisConstants.CP_NSNAME));
                    // Use a map to handle the unsupported scenario when an alias has more than one member
                    // in this code the alias will arbitrarily have the the last members discovered.
                    // this is needed to ensure code dependent on this code does not receive duplicates
                    aliases.put(alias.getName(), alias);
                    _log.debug("Retreived alias name " + alias.getName() + " and address " + alias.getAddress());
                } catch (Exception e) {
                    // if the WWN is not a valid one and setAddress will throw an error
                    // Catch it , log it , skip it it and move forward with processing the rest of the data
                    _log.warn("An exception was encountered while processing " + wwn + " may be it is malformed " + e.getMessage());
                }
            }
        }
    } catch (Exception ex) {
        _log.warn("An exception was encountered while getting the aliases for " + "fabric: " + fabricId + ". The exception is: " + ex.getMessage());
    } finally {
        if (it != null) {
            it.close();
        }
    }
    return new ArrayList<ZoneWwnAlias>(aliases.values());
}
Also used : HashMap(java.util.HashMap) CIMObjectPath(javax.cim.CIMObjectPath) ArrayList(java.util.ArrayList) ZoneWwnAlias(com.emc.storageos.networkcontroller.impl.mds.ZoneWwnAlias) CIMInstance(javax.cim.CIMInstance) WBEMException(javax.wbem.WBEMException) NetworkControllerSessionLockedException(com.emc.storageos.networkcontroller.exceptions.NetworkControllerSessionLockedException) NetworkDeviceControllerException(com.emc.storageos.networkcontroller.exceptions.NetworkDeviceControllerException)

Example 4 with ZoneWwnAlias

use of com.emc.storageos.networkcontroller.impl.mds.ZoneWwnAlias in project coprhd-controller by CoprHD.

the class BrocadeNetworkSystemDevice method executeInSession.

/**
 * Common code for opening sessions and executing alias-type commands
 *
 * @param networkSystem the network system when the commands will execute
 * @param aliases a list of aliases to be created/updated/deleted
 * @param fabricId the name of fabric where the aliases will be changed
 * @param fabricWwn the WWN of fabric where the aliases will be changed
 * @param methodName the method to be executed
 * @param methodLogName the method name to be used for logging
 * @return the command that contains a map of results-per-alias keyed
 *         by alias name
 * @throws NetworkDeviceControllerException
 */
private BiosCommandResult executeInSession(NetworkSystem networkSystem, List<ZoneWwnAlias> aliases, String fabricId, String fabricWwn, String methodName, String methodLogName) throws NetworkDeviceControllerException {
    // a alias-name-to-result map to hold the results for each alias
    Map<String, String> aliasUpdateResults = new HashMap<String, String>();
    if (aliases.isEmpty()) {
        throw DeviceControllerException.exceptions.entityNullOrEmpty("aliases");
    }
    WBEMClient client = getNetworkDeviceClient(networkSystem);
    CIMInstance zoneServiceIns = null;
    try {
        if (fabricWwn == null) {
            fabricWwn = _smisHelper.getFabricWwn(client, fabricId);
        } else {
            validateFabric(networkSystem, fabricWwn, fabricId);
        }
        _log.info("{} started.", methodLogName);
        _log.info("Attempting to start a zoning session");
        zoneServiceIns = _smisHelper.startSession(client, fabricId, fabricWwn);
        if (zoneServiceIns == null) {
            _log.info("Failed to start a zoning session.");
            throw NetworkDeviceControllerException.exceptions.startZoningSessionFailed();
        }
        Method method = getClass().getMethod(methodName, new Class[] { WBEMClient.class, CIMInstance.class, String.class, String.class, ZoneWwnAlias.class });
        for (ZoneWwnAlias alias : aliases) {
            try {
                if ((Boolean) method.invoke(this, client, zoneServiceIns, fabricId, fabricWwn, alias)) {
                    aliasUpdateResults.put(alias.getName(), SUCCESS);
                } else {
                    aliasUpdateResults.put(alias.getName(), NO_CHANGE);
                }
            } catch (Exception ex) {
                aliasUpdateResults.put(alias.getName(), ERROR + " : " + ex.getMessage());
                _log.info("Exception was encountered but will try the rest of the batch. Error message: ", ex);
            }
        }
        _log.info("Attempting to close zoning session.");
        // If no aliases were changed, just close the session without commit and return.
        if (!hasResult(aliasUpdateResults, SUCCESS)) {
            _log.info("{} was not successful for any entity. Closing the session with no commit", methodLogName);
            if (!_smisHelper.endSession(client, zoneServiceIns, false)) {
                _log.info("Failed to terminate zoning session. Ignoring as session may have expired.");
            }
        } else {
            // if aliases were changed, commit them before ending the session
            if (!_smisHelper.endSession(client, zoneServiceIns, true)) {
                throw NetworkDeviceControllerException.exceptions.zoneSessionCommitFailed(fabricId);
            }
        }
        _log.info("{} completed successfully.", methodLogName);
    } catch (Exception e1) {
        try {
            if (zoneServiceIns != null) {
                _log.info("Attempting to terminate zoning session.");
                _smisHelper.endSession(client, zoneServiceIns, false);
            }
        } catch (WBEMException e) {
            _log.error("Failed to terminate zoning session." + e.getLocalizedMessage(), e);
        }
        _log.error("Failed to " + methodLogName + ": " + e1.getLocalizedMessage(), e1);
        throw NetworkDeviceControllerException.exceptions.operationFailed(methodLogName, e1);
    }
    _log.info(methodLogName + " results: " + toMessage(aliasUpdateResults));
    return getBiosCommandResult(aliasUpdateResults);
}
Also used : HashMap(java.util.HashMap) Method(java.lang.reflect.Method) WBEMClient(javax.wbem.client.WBEMClient) WBEMException(javax.wbem.WBEMException) ZoneWwnAlias(com.emc.storageos.networkcontroller.impl.mds.ZoneWwnAlias) CIMInstance(javax.cim.CIMInstance) WBEMException(javax.wbem.WBEMException) DeviceControllerException(com.emc.storageos.exceptions.DeviceControllerException) NetworkDeviceControllerException(com.emc.storageos.networkcontroller.exceptions.NetworkDeviceControllerException)

Example 5 with ZoneWwnAlias

use of com.emc.storageos.networkcontroller.impl.mds.ZoneWwnAlias in project coprhd-controller by CoprHD.

the class BrocadeNetworkSystemDevice method checkAndUpdateAlias.

/**
 * Check if an alias exists before removing it. If the alias does not exist
 * then nothing will be done.
 *
 * @param client an instance of WBEMClient
 * @param zoneServiceIns the zone service holding the zoning session
 * @param fabricId the fabric name
 * @param fabricWwn the fabric WWN
 * @param updateAlias the alias to be created
 * @return true if an alias was indeed created
 * @throws WBEMException
 */
public boolean checkAndUpdateAlias(WBEMClient client, CIMInstance zoneServiceIns, String fabricId, String fabricWwn, ZoneWwnAlias alias) throws WBEMException {
    boolean success = false;
    ZoneWwnAliasUpdate updateAlias = (ZoneWwnAliasUpdate) alias;
    _log.info("Starting update alias {}", updateAlias.getName());
    // check if the alias exists
    ZoneWwnAlias existingAlias = _smisHelper.getAlias(client, updateAlias.getName(), fabricWwn, true);
    if (existingAlias != null) {
        _log.info("Found alias {}", updateAlias.getName());
        // check if the alias is how we expect it to be
        if (!StringUtils.isEmpty(updateAlias.getNewName())) {
            _log.warn("Rename alias is request and is not supported for Brocade.", existingAlias.getName());
            if (StringUtils.equals(existingAlias.getName(), updateAlias.getNewName())) {
                _log.info("The existing alias already has the requested name {}. Ignoring.", existingAlias.getName());
            } else {
                _log.error("A request is made to update alias name from {} to {}. Rename is not supported for Brocade", existingAlias.getName(), updateAlias.getNewName());
                throw NetworkDeviceControllerException.exceptions.renameAliasNotSupported(alias.getName());
            }
        }
        // check if the alias is how we expect it to be
        if (!StringUtils.isEmpty(updateAlias.getAddress()) && !StringUtils.equalsIgnoreCase(existingAlias.getAddress(), updateAlias.getAddress())) {
            _log.info("The existing alias has a WWN other than the expected {}. It will not be updated.", updateAlias.getAddress());
            throw NetworkDeviceControllerException.exceptions.aliasWithDifferentWwnExists(alias.getName(), existingAlias.getAddress(), updateAlias.getAddress());
        }
        if (!StringUtils.isEmpty(updateAlias.getNewAddress())) {
            if (StringUtils.equalsIgnoreCase(existingAlias.getAddress(), updateAlias.getNewAddress())) {
                _log.info("The existing alias already has the requested WWN {}. WWN will not change.", existingAlias.getAddress());
            } else {
                _log.info("Updating alias member from {} to {}", existingAlias.getAddress(), updateAlias.getNewAddress());
                _smisHelper.removeZoneOrAliasMember(client, (CIMObjectPath) existingAlias.getCimMemberPath(), (CIMObjectPath) existingAlias.getCimObjectPath(), false);
                success = _smisHelper.addZoneOrAliasMember(client, zoneServiceIns, fabricWwn, (CIMObjectPath) existingAlias.getCimObjectPath(), updateAlias.getNewAddress());
                // If member change fails, exit this function
                if (!success) {
                    return success;
                }
            }
        }
    } else {
        throw NetworkDeviceControllerException.exceptions.aliasNotFound(updateAlias.getName());
    }
    return success;
}
Also used : CIMObjectPath(javax.cim.CIMObjectPath) ZoneWwnAliasUpdate(com.emc.storageos.networkcontroller.impl.mds.ZoneWwnAliasUpdate) ZoneWwnAlias(com.emc.storageos.networkcontroller.impl.mds.ZoneWwnAlias)

Aggregations

ZoneWwnAlias (com.emc.storageos.networkcontroller.impl.mds.ZoneWwnAlias)9 NetworkSystem (com.emc.storageos.db.client.model.NetworkSystem)3 NetworkDeviceControllerException (com.emc.storageos.networkcontroller.exceptions.NetworkDeviceControllerException)3 ArrayList (java.util.ArrayList)3 MapNetworkSystem (com.emc.storageos.api.mapper.functions.MapNetworkSystem)2 Operation (com.emc.storageos.db.client.model.Operation)2 DeviceControllerException (com.emc.storageos.exceptions.DeviceControllerException)2 WwnAliasParam (com.emc.storageos.model.network.WwnAliasParam)2 NetworkController (com.emc.storageos.networkcontroller.NetworkController)2 CheckPermission (com.emc.storageos.security.authorization.CheckPermission)2 HashMap (java.util.HashMap)2 CIMInstance (javax.cim.CIMInstance)2 CIMObjectPath (javax.cim.CIMObjectPath)2 WBEMException (javax.wbem.WBEMException)2 Consumes (javax.ws.rs.Consumes)2 POST (javax.ws.rs.POST)2 Path (javax.ws.rs.Path)2 Produces (javax.ws.rs.Produces)2 DatabaseException (com.emc.storageos.db.exceptions.DatabaseException)1 NetworkControllerSessionLockedException (com.emc.storageos.networkcontroller.exceptions.NetworkControllerSessionLockedException)1