Search in sources :

Example 66 with VPlexApiClient

use of com.emc.storageos.vplex.api.VPlexApiClient in project coprhd-controller by CoprHD.

the class VPlexCacheStatusJob method getVPlexAPIClient.

/**
 * Get the HTTP client for making requests to the VPlex at the endpoint
 * specified in the passed profile.
 *
 * @param jobContext The job context
 * @param vplexSystem The VPlex storage system
 *
 * @return A reference to the VPlex API HTTP client.
 * @throws URISyntaxException
 */
private VPlexApiClient getVPlexAPIClient(JobContext jobContext, StorageSystem vplexSystem) throws URISyntaxException {
    // Create the URI to access the VPlex Management Station based
    // on the IP and port for the passed VPlex system.
    URI vplexEndpointURI = new URI("https", null, vplexSystem.getIpAddress(), vplexSystem.getPortNumber(), "/", null, null);
    s_logger.debug("VPlex base URI is {}", vplexEndpointURI.toString());
    VPlexApiFactory vplexApiFactory = jobContext.getVPlexApiFactory();
    s_logger.debug("Got VPlex API factory");
    VPlexApiClient client = vplexApiFactory.getClient(vplexEndpointURI, vplexSystem.getUsername(), vplexSystem.getPassword());
    s_logger.debug("Got VPlex API client");
    return client;
}
Also used : VPlexApiClient(com.emc.storageos.vplex.api.VPlexApiClient) URI(java.net.URI) VPlexApiFactory(com.emc.storageos.vplex.api.VPlexApiFactory)

Example 67 with VPlexApiClient

use of com.emc.storageos.vplex.api.VPlexApiClient in project coprhd-controller by CoprHD.

the class VPlexMigrationJob method poll.

/**
 * {@inheritDoc}
 */
public JobPollResult poll(JobContext jobContext, long trackingPeriodInMillis) {
    s_logger.debug("Polled migration job");
    Migration migration = null;
    StorageSystem vplexSystem = null;
    try {
        // Therefore, the default max retries is 240.
        if (_maxRetries == null) {
            if (trackingPeriodInMillis < MAX_TIME_FOR_SUCCESSFUL_STATUS_CHECK_MS) {
                _maxRetries = new Integer(Math.round(MAX_TIME_FOR_SUCCESSFUL_STATUS_CHECK_MS / trackingPeriodInMillis));
            } else {
                _maxRetries = new Integer(1);
            }
        }
        // Get the DB client from the job context.
        DbClient dbClient = jobContext.getDbClient();
        // Get the migration associated with this job.
        migration = dbClient.queryObject(Migration.class, _taskCompleter.getId());
        String migrationName = migration.getLabel();
        s_logger.debug("Migration is {}", migration.getId());
        // Get the virtual volume associated with the migration
        // and then get the VPlex storage system for that virtual
        // volume.
        Volume virtualVolume = dbClient.queryObject(Volume.class, migration.getVolume());
        s_logger.debug("Virtual volume is {}", virtualVolume.getId());
        vplexSystem = dbClient.queryObject(StorageSystem.class, virtualVolume.getStorageController());
        s_logger.debug("VPlex system is {}", vplexSystem.getId());
        // Get the VPlex API client for this VPlex storage system
        // and get the latest info for the migration.
        VPlexApiClient vplexApiClient = VPlexControllerUtils.getVPlexAPIClient(jobContext.getVPlexApiFactory(), vplexSystem, dbClient);
        s_logger.debug("Got VPlex APi Client");
        VPlexMigrationInfo migrationInfo = vplexApiClient.getMigrationInfo(migrationName);
        s_logger.debug("Got migration info from VPlex");
        // Update the migration in the database to reflect the
        // current status and percent done.
        String migrationStatus = migrationInfo.getStatus();
        s_logger.debug("Migration status is {}", migrationStatus);
        migration.setMigrationStatus(migrationStatus);
        int percentDone = getMigrationPercentDone(migrationInfo.getPercentageDone());
        s_logger.debug("Migration percent done is {}", percentDone);
        migration.setPercentDone(String.valueOf(percentDone));
        dbClient.persistObject(migration);
        // Update the job info.
        _pollResult.setJobName(migrationName);
        _pollResult.setJobId(virtualVolume.getId().toString());
        _pollResult.setJobPercentComplete(percentDone);
        s_logger.debug("Updated poll result");
        // Examine the status.
        if (VPlexMigrationInfo.MigrationStatus.COMPLETE.getStatusValue().equals(migrationStatus)) {
            // Completed successfully
            s_logger.info("Migration: {} completed sucessfully", migration.getId());
            _status = JobStatus.SUCCESS;
        } else if (VPlexMigrationInfo.MigrationStatus.COMMITTED.getStatusValue().equals(migrationStatus)) {
            // The migration job completed and somehow it was committed
            // outside the scope of the workflow that created the
            // migration job. We return success here to ensure that there
            // is no rollback in the workflow that could end up deleting
            // the target volume of the migration.
            s_logger.info("Migration: {} completed and was committed", migration.getId());
            _status = JobStatus.SUCCESS;
        } else if (VPlexMigrationInfo.MigrationStatus.CANCELLED.getStatusValue().equals(migrationStatus)) {
            // The migration job was cancelled outside the scope of the
            // workflow that created the migration job.
            _errorDescription = "The migration was cancelled";
            s_logger.info("Migration: {} was cancelled prior to completion", migration.getId());
            _status = JobStatus.FAILED;
        } else if (VPlexMigrationInfo.MigrationStatus.ERROR.getStatusValue().equals(migrationStatus)) {
            // The migration failed.
            _errorDescription = "The migration failed";
            s_logger.error("Migration {} failed prior to completion", migration.getId());
            _status = JobStatus.FAILED;
        }
        // We had a successful check of the status. Reset the retry
        // count in case the job is still in progress and the next
        // attempt to check the status fails.
        _retryCount = 0;
    } catch (Exception e) {
        s_logger.error(String.format("Unexpected error getting status of migration %s on VPlex %s: %s", (migration != null ? migration.getId() : "null"), (vplexSystem != null ? vplexSystem.getId() : "null"), _errorDescription), e);
        if (++_retryCount > _maxRetries) {
            _errorDescription = e.getMessage();
            _status = JobStatus.FAILED;
        }
    } finally {
        s_logger.debug("Updating status {}", _status);
        updateStatus(jobContext);
    }
    _pollResult.setJobStatus(_status);
    _pollResult.setErrorDescription(_errorDescription);
    return _pollResult;
}
Also used : VPlexMigrationInfo(com.emc.storageos.vplex.api.VPlexMigrationInfo) DbClient(com.emc.storageos.db.client.DbClient) Volume(com.emc.storageos.db.client.model.Volume) Migration(com.emc.storageos.db.client.model.Migration) VPlexApiClient(com.emc.storageos.vplex.api.VPlexApiClient) URISyntaxException(java.net.URISyntaxException) StorageSystem(com.emc.storageos.db.client.model.StorageSystem)

Example 68 with VPlexApiClient

use of com.emc.storageos.vplex.api.VPlexApiClient in project coprhd-controller by CoprHD.

the class VPlexCommunicationInterface method discoverAll.

/**
 * Implementation for discovering everything in a VPLEX storage system.
 *
 * @param accessProfile providing context for this discovery session
 *
 * @throws BaseCollectionException
 */
private void discoverAll(AccessProfile accessProfile) throws BaseCollectionException {
    boolean discoverySuccess = true;
    StringBuffer errMsgBuilder = new StringBuffer();
    URI storageSystemURI = null;
    StorageSystem vplexStorageSystem = null;
    String detailedStatusMessage = "Unknown Status";
    VPlexApiClient client = null;
    try {
        s_logger.info("Access Profile Details :  IpAddress : {}, PortNumber : {}", accessProfile.getIpAddress(), accessProfile.getPortNumber());
        storageSystemURI = accessProfile.getSystemId();
        // Get the VPlex storage system from the database.
        vplexStorageSystem = _dbClient.queryObject(StorageSystem.class, storageSystemURI);
        s_logger.info("Discover VPlex storage system {} at IP:{}, PORT:{}", new Object[] { storageSystemURI.toString(), accessProfile.getIpAddress(), accessProfile.getPortNumber() });
        // Get the Http client for getting information about the VPlex
        // storage system.
        client = getVPlexAPIClient(accessProfile);
        s_logger.debug("Got handle to VPlex API client");
        // clear cached discovery data in the VPlexApiClient
        client.clearCaches();
        client.primeCaches();
        // The version for the storage system is the version of its active provider
        // and since we are discovering it, the provider was compatible, so the
        // VPLEX must also be compatible.
        StorageProvider activeProvider = _dbClient.queryObject(StorageProvider.class, vplexStorageSystem.getActiveProviderURI());
        String serialNumber = getSystemSerialNumber(client, activeProvider, null);
        if (!vplexStorageSystem.getSerialNumber().equals(serialNumber)) {
            s_logger.error(String.format("The VPLEX serial number unexpectedly changed from %s to %s.", vplexStorageSystem.getSerialNumber(), serialNumber));
            throw VPlexApiException.exceptions.vplexSerialNumberChanged(vplexStorageSystem.getSerialNumber(), serialNumber);
        }
        vplexStorageSystem.setFirmwareVersion(activeProvider.getVersionString());
        vplexStorageSystem.setCompatibilityStatus(CompatibilityStatus.COMPATIBLE.toString());
        // Discover the cluster identification (serial number / cluster id ) mapping
        try {
            s_logger.info("Discovering cluster identification.");
            discoverClusterIdentification(vplexStorageSystem, client);
            _completer.statusPending(_dbClient, "Completed cluster identification discovery");
        } catch (VPlexCollectionException vce) {
            discoverySuccess = false;
            String errMsg = String.format("Failed cluster identification discovery for VPlex %s", storageSystemURI.toString());
            s_logger.error(errMsg, vce);
            if (errMsgBuilder.length() != 0) {
                errMsgBuilder.append(", ");
            }
            errMsgBuilder.append(errMsg);
        }
        List<StoragePort> allPorts = new ArrayList<StoragePort>();
        // Discover the VPlex port information.
        try {
            // When we discover storage ports on the VPlex, we create
            // initiators, if they don't exist, for backend ports.
            // The backend storage ports serve as initiators for the
            // connected backend storage.
            s_logger.info("Discovering frontend and backend ports.");
            discoverPorts(client, vplexStorageSystem, allPorts, null);
            _dbClient.updateObject(vplexStorageSystem);
            _completer.statusPending(_dbClient, "Completed port discovery");
        } catch (VPlexCollectionException vce) {
            discoverySuccess = false;
            String errMsg = String.format("Failed port discovery for VPlex %s", storageSystemURI.toString());
            s_logger.error(errMsg, vce);
            if (errMsgBuilder.length() != 0) {
                errMsgBuilder.append(", ");
            }
            errMsgBuilder.append(errMsg);
        }
        // update host initiators with registered initiator names from VPLEX
        try {
            updateHostInitiators(client, vplexStorageSystem.getSerialNumber());
        } catch (VPlexCollectionException vce) {
            discoverySuccess = false;
            String errMsg = String.format("Failed host initiator update for VPlex %s", storageSystemURI.toString());
            s_logger.error(errMsg, vce);
            if (errMsgBuilder.length() != 0) {
                errMsgBuilder.append(", ");
            }
            errMsgBuilder.append(errMsg);
        }
        try {
            s_logger.info("Discovering connectivity.");
            discoverConnectivity(vplexStorageSystem);
            _dbClient.updateObject(vplexStorageSystem);
            _completer.statusPending(_dbClient, "Completed connectivity verification");
        } catch (VPlexCollectionException vce) {
            discoverySuccess = false;
            String errMsg = String.format("Failed connectivity discovery for VPlex %s", storageSystemURI.toString());
            s_logger.error(errMsg, vce);
            if (errMsgBuilder.length() != 0) {
                errMsgBuilder.append(", ");
            }
            errMsgBuilder.append(errMsg);
        }
        if (discoverySuccess) {
            vplexStorageSystem.setReachableStatus(true);
            _dbClient.updateObject(vplexStorageSystem);
        } else {
            // If part of the discovery process failed, throw an exception.
            vplexStorageSystem.setReachableStatus(false);
            _dbClient.updateObject(vplexStorageSystem);
            throw new Exception(errMsgBuilder.toString());
        }
        StoragePortAssociationHelper.runUpdatePortAssociationsProcess(allPorts, null, _dbClient, _coordinator, null);
        // discovery succeeds
        detailedStatusMessage = String.format("Discovery completed successfully for Storage System: %s", storageSystemURI.toString());
    } catch (Exception e) {
        if (null != client) {
            // clear cached discovery data in the VPlexApiClient
            client.clearCaches();
        }
        VPlexCollectionException vce = VPlexCollectionException.exceptions.failedDiscovery(storageSystemURI.toString(), e.getLocalizedMessage());
        detailedStatusMessage = vce.getLocalizedMessage();
        s_logger.error(detailedStatusMessage, e);
        throw vce;
    } finally {
        if (vplexStorageSystem != null) {
            try {
                // set detailed message
                vplexStorageSystem.setLastDiscoveryStatusMessage(detailedStatusMessage);
                _dbClient.updateObject(vplexStorageSystem);
            } catch (DatabaseException ex) {
                s_logger.error("Error persisting last discovery status for storage system {}", vplexStorageSystem.getId(), ex);
            }
        }
    }
}
Also used : StoragePort(com.emc.storageos.db.client.model.StoragePort) ArrayList(java.util.ArrayList) StorageProvider(com.emc.storageos.db.client.model.StorageProvider) URI(java.net.URI) URISyntaxException(java.net.URISyntaxException) DatabaseException(com.emc.storageos.db.exceptions.DatabaseException) BaseCollectionException(com.emc.storageos.plugins.BaseCollectionException) VPlexApiException(com.emc.storageos.vplex.api.VPlexApiException) VPlexCollectionException(com.emc.storageos.plugins.metering.vplex.VPlexCollectionException) IOException(java.io.IOException) VPlexCollectionException(com.emc.storageos.plugins.metering.vplex.VPlexCollectionException) VPlexApiClient(com.emc.storageos.vplex.api.VPlexApiClient) DatabaseException(com.emc.storageos.db.exceptions.DatabaseException) StorageSystem(com.emc.storageos.db.client.model.StorageSystem)

Example 69 with VPlexApiClient

use of com.emc.storageos.vplex.api.VPlexApiClient in project coprhd-controller by CoprHD.

the class VPlexCommunicationInterface method getVPlexAPIClient.

/**
 * Get the HTTP client for making requests to the VPlex at the
 * endpoint specified in the passed profile.
 *
 * @param accessProfile A reference to the access profile.
 *
 * @return A reference to the VPlex API HTTP client.
 * @throws URISyntaxException
 */
private VPlexApiClient getVPlexAPIClient(AccessProfile accessProfile) throws URISyntaxException {
    // Create the URI to access the VPlex Management Station based
    // on the IP and port in the passed access profile.
    URI vplexEndpointURI = new URI("https", null, accessProfile.getIpAddress(), accessProfile.getPortNumber(), "/", null, null);
    s_logger.debug("VPlex base URI is {}", vplexEndpointURI.toString());
    VPlexApiClient client = _apiFactory.getClient(vplexEndpointURI, accessProfile.getUserName(), accessProfile.getPassword());
    return client;
}
Also used : VPlexApiClient(com.emc.storageos.vplex.api.VPlexApiClient) URI(java.net.URI)

Example 70 with VPlexApiClient

use of com.emc.storageos.vplex.api.VPlexApiClient in project coprhd-controller by CoprHD.

the class VPlexCommunicationInterface method scan.

/**
 * Implementation for scan for VPlex storage systems.
 *
 * @param accessProfile
 *
 * @throws BaseCollectionException
 */
@Override
public void scan(AccessProfile accessProfile) throws BaseCollectionException {
    URI mgmntServerURI = accessProfile.getSystemId();
    StorageProvider mgmntServer = null;
    String scanStatusMessage = "Unknown Status";
    VPlexApiClient client = null;
    try {
        // Get the storage provider representing a VPLEX management server.
        mgmntServer = _dbClient.queryObject(StorageProvider.class, mgmntServerURI);
        // Get the Http client for getting information about the VPLEX
        // cluster(s) managed by the VPLEX management server.
        client = getVPlexAPIClient(accessProfile);
        s_logger.debug("Got handle to VPlex API client");
        // Verify the connectivity to the VPLEX management server.
        verifyConnectivity(client, mgmntServer);
        // Verify the VPLEX system firmware version is supported.
        verifyMinimumSupportedFirmwareVersion(client, mgmntServer);
        // Determine the VPLEX system managed by this management server.
        Map<String, StorageSystemViewObject> scanCache = accessProfile.getCache();
        s_logger.info("Storage System scanCache before scanning:" + scanCache);
        scanManagedSystems(client, mgmntServer, scanCache);
        s_logger.info("Storage System scanCache after scanning:" + scanCache);
        scanStatusMessage = String.format("Scan job completed successfully for " + "VPLEX management server: %s", mgmntServerURI.toString());
    } catch (Exception e) {
        if (null != client) {
            // clear cached discovery data in the VPlexApiClient
            client.clearCaches();
        }
        VPlexCollectionException vce = VPlexCollectionException.exceptions.failedScan(mgmntServer.getIPAddress(), e.getLocalizedMessage());
        scanStatusMessage = vce.getLocalizedMessage();
        throw vce;
    } finally {
        if (mgmntServer != null) {
            try {
                mgmntServer.setLastScanStatusMessage(scanStatusMessage);
                _dbClient.updateObject(mgmntServer);
            } catch (Exception e) {
                s_logger.error("Error persisting scan status message for management server {}", mgmntServerURI.toString(), e);
            }
        }
    }
}
Also used : VPlexCollectionException(com.emc.storageos.plugins.metering.vplex.VPlexCollectionException) StorageSystemViewObject(com.emc.storageos.plugins.StorageSystemViewObject) VPlexApiClient(com.emc.storageos.vplex.api.VPlexApiClient) StorageProvider(com.emc.storageos.db.client.model.StorageProvider) URI(java.net.URI) URISyntaxException(java.net.URISyntaxException) DatabaseException(com.emc.storageos.db.exceptions.DatabaseException) BaseCollectionException(com.emc.storageos.plugins.BaseCollectionException) VPlexApiException(com.emc.storageos.vplex.api.VPlexApiException) VPlexCollectionException(com.emc.storageos.plugins.metering.vplex.VPlexCollectionException) IOException(java.io.IOException)

Aggregations

VPlexApiClient (com.emc.storageos.vplex.api.VPlexApiClient)81 VPlexApiException (com.emc.storageos.vplex.api.VPlexApiException)57 URISyntaxException (java.net.URISyntaxException)57 ControllerException (com.emc.storageos.volumecontroller.ControllerException)55 WorkflowException (com.emc.storageos.workflow.WorkflowException)55 InternalException (com.emc.storageos.svcs.errorhandling.resources.InternalException)54 StorageSystem (com.emc.storageos.db.client.model.StorageSystem)52 DeviceControllerException (com.emc.storageos.exceptions.DeviceControllerException)52 InternalServerErrorException (com.emc.storageos.svcs.errorhandling.resources.InternalServerErrorException)52 DatabaseException (com.emc.storageos.db.exceptions.DatabaseException)48 IOException (java.io.IOException)47 URI (java.net.URI)41 ServiceError (com.emc.storageos.svcs.errorhandling.model.ServiceError)40 Volume (com.emc.storageos.db.client.model.Volume)34 ArrayList (java.util.ArrayList)34 NamedURI (com.emc.storageos.db.client.model.NamedURI)26 HashMap (java.util.HashMap)18 ExportMask (com.emc.storageos.db.client.model.ExportMask)16 VPlexStorageViewInfo (com.emc.storageos.vplex.api.VPlexStorageViewInfo)16 VPlexVirtualVolumeInfo (com.emc.storageos.vplex.api.VPlexVirtualVolumeInfo)16