Search in sources :

Example 1 with BiosCommandResult

use of com.emc.storageos.volumecontroller.impl.BiosCommandResult in project coprhd-controller by CoprHD.

the class RPHelper method cleanupSnapshots.

/**
 * Validate Block snapshots that correspond to RP bookmarks. Some may no longer exist in the RP system, and we
 * need to mark them as invalid.
 *
 * The strategy is as follows:
 * 1. Get all of the protection sets associated with the protection system
 * 2. Are there any Block Snapshots of type RP? (if not, don't bother cleaning up)
 * 3. Query the RP Appliance for all bookmarks for that CG (protection set)
 * 4. Find each block snapshot of type RP for each site
 * 5. If you can't find the bookmark in the RP list, move the block snapshot to inactive
 *
 * @param protectionSystem Protection System
 */
public static void cleanupSnapshots(DbClient dbClient, ProtectionSystem protectionSystem) throws RecoverPointException {
    // 1. Get all of the protection sets associated with the protection system
    Set<URI> protectionSetIDs = new HashSet<URI>();
    Set<Integer> cgIDs = new HashSet<Integer>();
    URIQueryResultList list = new URIQueryResultList();
    Constraint constraint = ContainmentConstraint.Factory.getProtectionSystemProtectionSetConstraint(protectionSystem.getId());
    dbClient.queryByConstraint(constraint, list);
    Iterator<URI> it = list.iterator();
    while (it.hasNext()) {
        URI protectionSetId = it.next();
        // Get all snapshots that are part of this protection set.
        URIQueryResultList plist = new URIQueryResultList();
        Constraint pconstraint = ContainmentConstraint.Factory.getProtectionSetBlockSnapshotConstraint(protectionSetId);
        dbClient.queryByConstraint(pconstraint, plist);
        if (plist.iterator().hasNext()) {
            // OK, we know there are snapshots for this protection set/CG.
            // Retrieve all of the bookmarks associated with this protection set/CG later on by adding to the list now
            ProtectionSet protectionSet = dbClient.queryObject(ProtectionSet.class, protectionSetId);
            if (protectionSet != null && !protectionSet.getInactive()) {
                protectionSetIDs.add(protectionSet.getId());
                cgIDs.add(Integer.valueOf(protectionSet.getProtectionId()));
            }
        }
    }
    // 2. No reason to bother the RPAs if there are no protection sets for this protection system.
    if (protectionSetIDs.isEmpty()) {
        _log.info("Block Snapshot of RP Bookmarks cleanup not run for this protection system. No Protections or RP Block Snapshots found on protection system: " + protectionSystem.getLabel());
        return;
    }
    // 3. Query the RP appliance for all of the bookmarks for these CGs in one call
    BiosCommandResult result = getRPBookmarks(protectionSystem, cgIDs);
    GetBookmarksResponse bookmarkMap = (GetBookmarksResponse) result.getObjectList().get(0);
    // 4. Go through each protection set's snapshots and see if they're there.
    it = protectionSetIDs.iterator();
    while (it.hasNext()) {
        URI protectionSetId = it.next();
        ProtectionSet protectionSet = dbClient.queryObject(ProtectionSet.class, protectionSetId);
        // The map should have an entry for that CG with an empty list if it looked and couldn't find any. (a successful empty set)
        if (protectionSet.getProtectionId() != null && bookmarkMap.getCgBookmarkMap() != null && bookmarkMap.getCgBookmarkMap().containsKey(new Integer(protectionSet.getProtectionId()))) {
            // list to avoid issues further down.
            if (bookmarkMap.getCgBookmarkMap().get(new Integer(protectionSet.getProtectionId())) == null) {
                bookmarkMap.getCgBookmarkMap().put(new Integer(protectionSet.getProtectionId()), new ArrayList<RPBookmark>());
            }
            // Get all snapshots that are part of this protection set.
            URIQueryResultList plist = new URIQueryResultList();
            Constraint pconstraint = ContainmentConstraint.Factory.getProtectionSetBlockSnapshotConstraint(protectionSetId);
            dbClient.queryByConstraint(pconstraint, plist);
            Iterator<URI> snapshotIter = plist.iterator();
            while (snapshotIter.hasNext()) {
                URI snapshotId = snapshotIter.next();
                BlockSnapshot snapshot = dbClient.queryObject(BlockSnapshot.class, snapshotId);
                boolean deleteSnapshot = true;
                if (snapshot.getInactive()) {
                    // Don't bother deleting or processing if the snapshot is already on its way out.
                    deleteSnapshot = false;
                } else if (snapshot.getEmCGGroupCopyId() == null) {
                    // If something bad happened and we weren't able to get the site information off of the snapshot
                    _log.info("Found that ViPR Snapshot corresponding to RP Bookmark is missing Site information, thus not analyzing for automated deletion. " + snapshot.getId() + " - " + protectionSet.getLabel() + ":" + snapshot.getEmInternalSiteName() + ":" + snapshot.getEmName());
                    deleteSnapshot = false;
                } else if (!bookmarkMap.getCgBookmarkMap().get(Integer.valueOf(protectionSet.getProtectionId())).isEmpty()) {
                    for (RPBookmark bookmark : bookmarkMap.getCgBookmarkMap().get(Integer.valueOf(protectionSet.getProtectionId()))) {
                        // bookmark (from RP) vs. snapshot (from ViPR)
                        if (snapshot.getEmName().equalsIgnoreCase(bookmark.getBookmarkName()) && snapshot.getEmCGGroupCopyId().equals(bookmark.getCGGroupCopyUID().getGlobalCopyUID().getCopyUID())) {
                            deleteSnapshot = false;
                            _log.info("Found that ViPR Snapshot corresponding to RP Bookmark still exists, thus saving in ViPR: " + snapshot.getId() + " - " + protectionSet.getLabel() + ":" + snapshot.getEmInternalSiteName() + ":" + snapshot.getEmCGGroupCopyId() + ":" + snapshot.getEmName());
                        }
                    }
                } else {
                    // Just for debugging, otherwise useless
                    _log.debug("Found that ViPR Snapshot corresponding to RP Bookmark doesn't exist, thus going to delete from ViPR: " + snapshot.getId() + " - " + protectionSet.getLabel() + ":" + snapshot.getEmInternalSiteName() + ":" + snapshot.getEmCGGroupCopyId() + ":" + snapshot.getEmName());
                }
                if (deleteSnapshot) {
                    // 5. We couldn't find the bookmark, and the query for it was successful, so it's time to mark it as gone
                    _log.info("Found that ViPR Snapshot corresponding to RP Bookmark no longer exists, thus deleting in ViPR: " + snapshot.getId() + " - " + protectionSet.getLabel() + ":" + snapshot.getEmInternalSiteName() + ":" + snapshot.getEmCGGroupCopyId() + ":" + snapshot.getEmName());
                    dbClient.markForDeletion(snapshot);
                }
            }
        } else if (protectionSet.getProtectionId() == null) {
            _log.error("Can not determine the consistency group ID of protection set: " + protectionSet.getLabel() + ", can not perform any cleanup of snapshots.");
        } else {
            _log.info("No consistency groups were found associated with protection system: " + protectionSystem.getLabel() + ", can not perform cleanup of snapshots.");
        }
    }
}
Also used : GetBookmarksResponse(com.emc.storageos.recoverpoint.responses.GetBookmarksResponse) Constraint(com.emc.storageos.db.client.constraint.Constraint) ContainmentConstraint(com.emc.storageos.db.client.constraint.ContainmentConstraint) ProtectionSet(com.emc.storageos.db.client.model.ProtectionSet) UnManagedProtectionSet(com.emc.storageos.db.client.model.UnManagedDiscoveredObjects.UnManagedProtectionSet) BlockSnapshot(com.emc.storageos.db.client.model.BlockSnapshot) NamedURI(com.emc.storageos.db.client.model.NamedURI) URI(java.net.URI) URIQueryResultList(com.emc.storageos.db.client.constraint.URIQueryResultList) BiosCommandResult(com.emc.storageos.volumecontroller.impl.BiosCommandResult) RPBookmark(com.emc.storageos.recoverpoint.objectmodel.RPBookmark) HashSet(java.util.HashSet)

Example 2 with BiosCommandResult

use of com.emc.storageos.volumecontroller.impl.BiosCommandResult in project coprhd-controller by CoprHD.

the class RPHelper method getRPBookmarks.

/**
 * For an RP configuration, get all RP bookmarks for the CGs provided
 *
 * @param system RP system
 * @param cgIDs IDs of the consistency groups to get the bookmarks
 * @return command result object, object list [0] has GetBookmarksResponse
 * @throws RecoverPointException
 */
private static BiosCommandResult getRPBookmarks(ProtectionSystem system, Set<Integer> cgIDs) throws RecoverPointException {
    _log.info("getRPBookmarks {} - start", system.getId());
    RecoverPointClient rp = RPHelper.getRecoverPointClient(system);
    GetBookmarksResponse bookmarkResponse = rp.getRPBookmarks(cgIDs);
    _log.info("getRPBookmarks {} - complete", system.getId());
    BiosCommandResult result = BiosCommandResult.createSuccessfulResult();
    List<Object> returnList = new ArrayList<Object>();
    returnList.add(bookmarkResponse);
    result.setObjectList(returnList);
    return result;
}
Also used : GetBookmarksResponse(com.emc.storageos.recoverpoint.responses.GetBookmarksResponse) BiosCommandResult(com.emc.storageos.volumecontroller.impl.BiosCommandResult) RecoverPointClient(com.emc.storageos.recoverpoint.impl.RecoverPointClient) ArrayList(java.util.ArrayList)

Example 3 with BiosCommandResult

use of com.emc.storageos.volumecontroller.impl.BiosCommandResult in project coprhd-controller by CoprHD.

the class NetworkDeviceController method zoneRollback.

/**
 * Rollback any of the zoning operations.
 *
 * @param exportGroupURI
 *            -- The ExportGroup URI
 * @param contextKey
 *            -- The context which indicates what zones were configured on the device.
 * @param taskId
 *            -- String task identifier for WorkflowTaskCompleter.
 * @return
 * @throws DeviceControllerException
 */
public boolean zoneRollback(URI exportGroupURI, String contextKey, String taskId) throws DeviceControllerException {
    TaskCompleter taskCompleter = null;
    try {
        NetworkFCContext context = (NetworkFCContext) WorkflowService.getInstance().loadStepData(contextKey);
        if (context == null) {
            _log.warn("No zone rollback information for Step: " + contextKey + " , Export Group: " + exportGroupURI.toString() + ", and Task: " + taskId + ". The zoning step either did not complete or encountered an error.");
            WorkflowStepCompleter.stepSucceded(taskId);
            return true;
        }
        logZones(context.getZoneInfos());
        WorkflowStepCompleter.stepExecuting(taskId);
        _log.info("Beginning zone rollback");
        _log.info("context.isAddingZones -{}", context.isAddingZones());
        // Determine what needs to be rolled back.
        List<NetworkFCZoneInfo> lastReferenceZoneInfo = new ArrayList<NetworkFCZoneInfo>();
        List<NetworkFCZoneInfo> rollbackList = new ArrayList<NetworkFCZoneInfo>();
        for (NetworkFCZoneInfo info : context.getZoneInfos()) {
            if (info.canBeRolledBack()) {
                // We should not blindly set last reference to true, removed code which does that earlier.
                rollbackList.add(info);
            } else {
                // Even though we cannot rollback the zone (because we didn't create it, it previously existed,
                // must remove the FCZoneReference that we created.
                deleteFCZoneReference(info);
            }
        }
        // Update the zone infos with the correct lastRef setting for those zones that can be rolled back
        _networkScheduler.determineIfLastZoneReferences(rollbackList);
        taskCompleter = new ZoneReferencesRemoveCompleter(NetworkUtil.getFCZoneReferences(rollbackList), context.isAddingZones(), taskId);
        InvokeTestFailure.internalOnlyInvokeTestFailure(InvokeTestFailure.ARTIFICIAL_FAILURE_020);
        // Changed this parameter to true, so that the last reference validation runs all the time in placeZones()
        BiosCommandResult result = addRemoveZones(exportGroupURI, rollbackList, true);
        InvokeTestFailure.internalOnlyInvokeTestFailure(InvokeTestFailure.ARTIFICIAL_FAILURE_021);
        if (result.isCommandSuccess() && !lastReferenceZoneInfo.isEmpty()) {
            _log.info("There seems to be last reference zones that were removed, clean those zones from the zoning map.");
            updateZoningMap(lastReferenceZoneInfo, exportGroupURI, null);
        }
        completeWorkflowState(taskCompleter, taskId, "ZoneRollback", result, null);
        return result.isCommandSuccess();
    } catch (Exception ex) {
        _log.error("Exception occurred while doing zone rollback", ex);
        ServiceError svcError = NetworkDeviceControllerException.errors.zoneRollbackFailedExc(exportGroupURI.toString(), ex);
        taskCompleter.error(_dbClient, svcError);
        WorkflowStepCompleter.stepFailed(taskId, svcError);
        return false;
    }
}
Also used : ServiceError(com.emc.storageos.svcs.errorhandling.model.ServiceError) NetworkFCZoneInfo(com.emc.storageos.networkcontroller.NetworkFCZoneInfo) BiosCommandResult(com.emc.storageos.volumecontroller.impl.BiosCommandResult) ArrayList(java.util.ArrayList) TaskCompleter(com.emc.storageos.volumecontroller.TaskCompleter) NetworkFCContext(com.emc.storageos.networkcontroller.NetworkFCContext) ZoneReferencesRemoveCompleter(com.emc.storageos.volumecontroller.impl.block.taskcompleter.ZoneReferencesRemoveCompleter) 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)

Example 4 with BiosCommandResult

use of com.emc.storageos.volumecontroller.impl.BiosCommandResult in project coprhd-controller by CoprHD.

the class NetworkDeviceController method addRemoveZones.

/**
 * Adds/removes a bunch of zones based on their NetworkFCZoneInfo structures.
 * They are split into groups and subgroups, first by the device/networkSystem used for zoning, and then by the fabricId to be zoned.
 * Then each subgroup is processed separately.
 *
 * @param exportGroupUri
 * @param fabricInfos
 * @return BiosCommandResult
 * @throws ControllerException
 */
public BiosCommandResult addRemoveZones(URI exportGroupUri, List<NetworkFCZoneInfo> fabricInfos, boolean doRemove) throws ControllerException {
    // Group the fabric infos together based on which devices should zone them.
    Map<URI, NetworkSystem> networkSystemId2NetworkSystem = new HashMap<URI, NetworkSystem>();
    Map<URI, List<NetworkFCZoneInfo>> networkSystemId2NetworkFabricInfos = new HashMap<>();
    for (NetworkFCZoneInfo fabricInfo : fabricInfos) {
        URI networkSystemId = fabricInfo.getNetworkDeviceId();
        URI altNetworkSystemId = fabricInfo.getAltNetworkDeviceId();
        NetworkSystem networkSystem = null;
        // Determine network system. The network system structures are cached in networkSystemId2NetworkSystem
        networkSystem = networkSystemId2NetworkSystem.get(networkSystemId);
        if (networkSystem == null) {
            networkSystem = getNetworkSystemObject(networkSystemId);
            if (networkSystem != null && networkSystem.getInactive() == false) {
                networkSystemId2NetworkSystem.put(networkSystemId, networkSystem);
            } else if (altNetworkSystemId != null) {
                networkSystem = networkSystemId2NetworkSystem.get(altNetworkSystemId);
                if (networkSystem == null) {
                    networkSystem = getNetworkSystemObject(altNetworkSystemId);
                    if (networkSystem != null && networkSystem.getInactive() == false) {
                        networkSystemId2NetworkSystem.put(altNetworkSystemId, networkSystem);
                    }
                }
            }
        }
        if (networkSystem == null) {
            throw NetworkDeviceControllerException.exceptions.addRemoveZonesFailedNoDev(networkSystemId.toString());
        }
        List<NetworkFCZoneInfo> finfos = networkSystemId2NetworkFabricInfos.get(networkSystem.getId());
        if (finfos == null) {
            finfos = new ArrayList<NetworkFCZoneInfo>();
            networkSystemId2NetworkFabricInfos.put(networkSystem.getId(), finfos);
        }
        finfos.add(fabricInfo);
    }
    // Now loop through each network system, splitting the collection of fabric infos by fabric ID/WWN.
    StringBuilder messageBuffer = new StringBuilder();
    for (URI deviceId : networkSystemId2NetworkFabricInfos.keySet()) {
        NetworkSystem device = networkSystemId2NetworkSystem.get(deviceId);
        Map<String, List<NetworkFCZoneInfo>> fabric2FabricInfos = new HashMap<String, List<NetworkFCZoneInfo>>();
        Map<String, NetworkLite> fabricId2Network = new HashMap<String, NetworkLite>();
        List<NetworkFCZoneInfo> finfos = networkSystemId2NetworkFabricInfos.get(deviceId);
        for (NetworkFCZoneInfo fabricInfo : finfos) {
            String fabricId = fabricInfo.getFabricId();
            String fabricWwn = fabricInfo.getFabricWwn();
            String key = (fabricWwn != null) ? fabricWwn : fabricId;
            updateAltDeviceid(fabricInfo, fabricId, fabricWwn, key, fabricId2Network);
            List<NetworkFCZoneInfo> singleFabricInfos = fabric2FabricInfos.get(key);
            if (singleFabricInfos == null) {
                singleFabricInfos = new ArrayList<NetworkFCZoneInfo>();
                fabric2FabricInfos.put(key, singleFabricInfos);
            }
            singleFabricInfos.add(fabricInfo);
        }
        // Now for each fabric, do the zoning.
        for (String key : fabric2FabricInfos.keySet()) {
            List<NetworkFCZoneInfo> singleFabricInfos = fabric2FabricInfos.get(key);
            String fabricId = singleFabricInfos.get(0).getFabricId();
            String fabricWwn = singleFabricInfos.get(0).getFabricWwn();
            BiosCommandResult rslt = addRemoveZones(device, fabricId, fabricWwn, exportGroupUri, singleFabricInfos, doRemove, true);
            if (messageBuffer.length() > 0) {
                messageBuffer.append("; ");
            }
            messageBuffer.append(rslt.getMessage());
        }
    }
    BiosCommandResult result = BiosCommandResult.createSuccessfulResult();
    return result;
}
Also used : HashMap(java.util.HashMap) NetworkLite(com.emc.storageos.util.NetworkLite) NetworkSystem(com.emc.storageos.db.client.model.NetworkSystem) URI(java.net.URI) NetworkFCZoneInfo(com.emc.storageos.networkcontroller.NetworkFCZoneInfo) BiosCommandResult(com.emc.storageos.volumecontroller.impl.BiosCommandResult) List(java.util.List) ArrayList(java.util.ArrayList) URIQueryResultList(com.emc.storageos.db.client.constraint.URIQueryResultList)

Example 5 with BiosCommandResult

use of com.emc.storageos.volumecontroller.impl.BiosCommandResult in project coprhd-controller by CoprHD.

the class NetworkDeviceController method connectNetwork.

@Override
public void connectNetwork(URI network) throws ControllerException {
    BiosCommandResult result = doConnect(network);
    boolean failed = false;
    if (!result.isCommandSuccess()) {
        _log.error("Connect failed to {}", network);
        failed = true;
    // To Do - mark device inactive or take in status to set failure.
    } else {
        String msg = MessageFormat.format("Connected to Network Device {0} at {1}", result.getMessage(), new Date());
        _log.info(msg);
    }
    // Update status on the NetworkSystem
    NetworkSystem networkObj = getNetworkSystemObject(network);
    networkObj.setCompatibilityStatus(failed ? DiscoveredDataObject.CompatibilityStatus.INCOMPATIBLE.name() : DiscoveredDataObject.CompatibilityStatus.COMPATIBLE.name());
    saveDeviceObject(networkObj);
}
Also used : BiosCommandResult(com.emc.storageos.volumecontroller.impl.BiosCommandResult) NetworkSystem(com.emc.storageos.db.client.model.NetworkSystem) Date(java.util.Date)

Aggregations

BiosCommandResult (com.emc.storageos.volumecontroller.impl.BiosCommandResult)135 DeviceControllerException (com.emc.storageos.exceptions.DeviceControllerException)76 ServiceError (com.emc.storageos.svcs.errorhandling.model.ServiceError)69 ControllerException (com.emc.storageos.volumecontroller.ControllerException)64 NetAppException (com.emc.storageos.netapp.NetAppException)34 ArrayList (java.util.ArrayList)34 NetworkDeviceControllerException (com.emc.storageos.networkcontroller.exceptions.NetworkDeviceControllerException)28 NetAppCException (com.emc.storageos.netappc.NetAppCException)19 DatabaseException (com.emc.storageos.db.exceptions.DatabaseException)18 NetAppApi (com.emc.storageos.netapp.NetAppApi)18 NetAppClusterApi (com.emc.storageos.netappc.NetAppClusterApi)18 URI (java.net.URI)16 VNXException (com.emc.storageos.vnx.xmlapi.VNXException)15 XMLApiResult (com.emc.storageos.vnx.xmlapi.XMLApiResult)15 VNXFileCommApi (com.emc.storageos.volumecontroller.impl.plugins.provisioning.VNXFileCommApi)15 ApplicationContext (org.springframework.context.ApplicationContext)15 ClassPathXmlApplicationContext (org.springframework.context.support.ClassPathXmlApplicationContext)15 FileShare (com.emc.storageos.db.client.model.FileShare)14 SMBFileShare (com.emc.storageos.db.client.model.SMBFileShare)14 NetworkSystem (com.emc.storageos.db.client.model.NetworkSystem)11