Search in sources :

Example 1 with ZoneUpdate

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

the class BrocadeNetworkSystemDevice method updateZonesStrategy.

/**
 * Updates one or more zones by adding/removing members as requested for each zone.
 *
 * @param client and instance of {@link WBEMClient} connected to the provider
 * @param zones the list of zone update requests
 * @param fabricId the name of the fabric where the zones exist
 * @param fabricWwn the WWN of the fabric where the zones exist
 * @param activateZones a boolean to indicate if the zoneset should be activated
 *            following successful updates
 * @return a map of the update results by zone keyed by zone name
 * @throws NetworkDeviceControllerException
 */
public Map<String, String> updateZonesStrategy(WBEMClient client, List<ZoneUpdate> zones, String fabricId, String fabricWwn, boolean activateZones) throws NetworkDeviceControllerException {
    // to do - Make sure fabric
    // id and fabric wwn are not
    // null or only request
    // needed params
    // a zone-name-to-result map to hold the results for each zone
    Map<String, String> zoneUpdateResults = new HashMap<String, String>();
    if (zones.isEmpty()) {
        throw DeviceControllerException.exceptions.entityNullOrEmpty("zones");
    }
    CIMInstance zoneServiceIns = null;
    try {
        _log.info("Update zones started.");
        _log.info("Attempting to start a zoning session");
        if (fabricWwn == null) {
            fabricWwn = _smisHelper.getFabricWwn(client, fabricId);
        }
        zoneServiceIns = _smisHelper.startSession(client, fabricId, fabricWwn);
        if (zoneServiceIns == null) {
            _log.info("Failed to start a zoning session.");
            throw NetworkDeviceControllerException.exceptions.startZoningSessionFailed();
        }
        // First determine if there is an active zoneset.
        CIMObjectPath zonesetPath = null;
        CIMInstance activeZonesetIns = _smisHelper.getActiveZonesetInstance(client, fabricId, fabricWwn);
        // There is no active zoneset, error
        if (activeZonesetIns == null) {
            _log.info("Cannot find active zoneset.");
            throw NetworkDeviceControllerException.exceptions.noActiveZonesetForFabric(fabricId);
        } else {
            // For Brocade, the active zoneset is a copy of a configuration zoneset. To make a change, we
            // need to modify the configuration zoneset and activate it. Get the configuration zoneset.
            zonesetPath = _smisHelper.getShadowZonesetPath(client, fabricId, fabricWwn, activeZonesetIns);
        }
        Map<String, Zone> zonesInFabric = _smisHelper.getZones(client, getZoneNames(zones), fabricWwn, false, true, true);
        for (ZoneUpdate zone : zones) {
            try {
                if (checkAndUpdateZone(client, zoneServiceIns, fabricId, fabricWwn, zonesetPath, zonesInFabric, zone)) {
                    zoneUpdateResults.put(zone.getName(), SUCCESS);
                } else {
                    zoneUpdateResults.put(zone.getName(), NO_CHANGE);
                }
            } catch (Exception ex) {
                zoneUpdateResults.put(zone.getName(), ERROR + " : " + ex.getMessage());
                handleZonesStrategyException(ex, activateZones);
            }
        }
        _log.info("Attempting to close zoning session.");
        // If there were no zones updated, just close the session without commit and return.
        if (!hasResult(zoneUpdateResults, SUCCESS)) {
            _log.info("No zones were updates. Closing the session with no commit");
            if (!_smisHelper.endSession(client, zoneServiceIns, false)) {
                _log.info("Failed to terminate zoning session. Ignoring as session may have expired.");
            }
        } else {
            // if zones were updated, commit them before ending the session
            if (_smisHelper.endSession(client, zoneServiceIns, true)) {
                if (activateZones) {
                    _log.info("Attempting to activate the zoneset.");
                    if (_smisHelper.activateZoneSet(client, zoneServiceIns, zonesetPath, true)) {
                        _log.info("The zoneset was activated succcessfully.");
                    } else {
                        _log.info("Failed to activate the zoneset");
                    }
                }
            } else {
                throw NetworkDeviceControllerException.exceptions.updateZonesStrategyFailedCommit();
            }
        }
        _log.info("Update zones strategy completed successfully.");
    } 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 update zones: " + e1.getLocalizedMessage(), e1);
        throw NetworkDeviceControllerException.exceptions.updateZonesStrategyFailed(e1);
    }
    return zoneUpdateResults;
}
Also used : HashMap(java.util.HashMap) Zone(com.emc.storageos.networkcontroller.impl.mds.Zone) CIMObjectPath(javax.cim.CIMObjectPath) ZoneUpdate(com.emc.storageos.networkcontroller.impl.mds.ZoneUpdate) WBEMException(javax.wbem.WBEMException) CIMInstance(javax.cim.CIMInstance) WBEMException(javax.wbem.WBEMException) DeviceControllerException(com.emc.storageos.exceptions.DeviceControllerException) NetworkDeviceControllerException(com.emc.storageos.networkcontroller.exceptions.NetworkDeviceControllerException)

Example 2 with ZoneUpdate

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

the class NetworkSystemService method updateSanZones.

/**
 * For given network system's fabric, update zones via add and/or remove their pwwns or aliases.
 * This is an asynchronous call.
 *
 * @param updateSanZones A parameter structure listing the zone(s) to be added and their members.
 * @param id the URN of a ViPR network system.
 * @param fabricId The name of the VSAN or fabric as returned by /vdc/network-systems/{id}/san-fabrics
 *            or the VSAN or fabric WWN
 * @prereq Updating zones must be exist in network system with given <code>id</code>
 * @brief Update SAN zones details for network system VSAN or fabric
 * @return A task description structure.
 * @throws InternalException
 */
@PUT
@Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Path("/{id}/san-fabrics/{fabricId}/san-zones")
@CheckPermission(roles = { Role.SYSTEM_ADMIN, Role.RESTRICTED_SYSTEM_ADMIN })
public TaskResourceRep updateSanZones(SanZoneUpdateParams updateSanZones, @PathParam("id") URI id, @PathParam("fabricId") String fabricId) throws InternalException {
    String task = UUID.randomUUID().toString();
    String fabricWwn = null;
    if (WWNUtility.isValidWWN(fabricId)) {
        fabricWwn = fabricId;
        fabricId = fabricId.replaceAll(":", "");
    }
    ArgValidator.checkFieldUriType(id, NetworkSystem.class, "id");
    NetworkSystem device = queryResource(id);
    List<ZoneUpdate> updateZones = new ArrayList<ZoneUpdate>();
    for (SanZoneUpdateParam sz : updateSanZones.getUpdateZones()) {
        ZoneUpdate updateZone = new ZoneUpdate(sz.getName());
        validateZoneName(sz.getName(), device.getSystemType());
        for (String szm : sz.getAddMembers()) {
            if (StringUtils.isEmpty(szm)) {
                continue;
            }
            ZoneMember member = createZoneMember(szm);
            updateZone.getAddZones().add(member);
        }
        for (String szm : sz.getRemoveMembers()) {
            if (StringUtils.isEmpty(szm)) {
                continue;
            }
            ZoneMember member = createZoneMember(szm);
            updateZone.getRemoveZones().add(member);
        }
        updateZones.add(updateZone);
        auditOp(OperationTypeEnum.UPDATE_SAN_ZONE, true, AuditLogManager.AUDITOP_BEGIN, updateZone.getName(), device.getId().toString(), device.getLabel(), device.getPortNumber(), device.getUsername(), device.getSmisProviderIP(), device.getSmisPortNumber(), device.getSmisUserName(), device.getSmisUseSSL(), device.getVersion(), device.getUptime());
    }
    ArgValidator.checkFieldNotEmpty(updateZones, "zones");
    Operation op = _dbClient.createTaskOpStatus(NetworkSystem.class, device.getId(), task, ResourceOperationTypeEnum.UPDATE_SAN_ZONE);
    NetworkController controller = getNetworkController(device.getSystemType());
    controller.updateSanZones(device.getId(), fabricId, fabricWwn, updateZones, false, task);
    return toTask(device, task, op);
}
Also used : NetworkSystem(com.emc.storageos.db.client.model.NetworkSystem) MapNetworkSystem(com.emc.storageos.api.mapper.functions.MapNetworkSystem) ArrayList(java.util.ArrayList) ZoneMember(com.emc.storageos.networkcontroller.impl.mds.ZoneMember) Operation(com.emc.storageos.db.client.model.Operation) ZoneUpdate(com.emc.storageos.networkcontroller.impl.mds.ZoneUpdate) SanZoneUpdateParam(com.emc.storageos.model.network.SanZoneUpdateParam) NetworkController(com.emc.storageos.networkcontroller.NetworkController) Path(javax.ws.rs.Path) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces) PUT(javax.ws.rs.PUT) CheckPermission(com.emc.storageos.security.authorization.CheckPermission)

Aggregations

ZoneUpdate (com.emc.storageos.networkcontroller.impl.mds.ZoneUpdate)2 MapNetworkSystem (com.emc.storageos.api.mapper.functions.MapNetworkSystem)1 NetworkSystem (com.emc.storageos.db.client.model.NetworkSystem)1 Operation (com.emc.storageos.db.client.model.Operation)1 DeviceControllerException (com.emc.storageos.exceptions.DeviceControllerException)1 SanZoneUpdateParam (com.emc.storageos.model.network.SanZoneUpdateParam)1 NetworkController (com.emc.storageos.networkcontroller.NetworkController)1 NetworkDeviceControllerException (com.emc.storageos.networkcontroller.exceptions.NetworkDeviceControllerException)1 Zone (com.emc.storageos.networkcontroller.impl.mds.Zone)1 ZoneMember (com.emc.storageos.networkcontroller.impl.mds.ZoneMember)1 CheckPermission (com.emc.storageos.security.authorization.CheckPermission)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 CIMInstance (javax.cim.CIMInstance)1 CIMObjectPath (javax.cim.CIMObjectPath)1 WBEMException (javax.wbem.WBEMException)1 Consumes (javax.ws.rs.Consumes)1 PUT (javax.ws.rs.PUT)1 Path (javax.ws.rs.Path)1 Produces (javax.ws.rs.Produces)1