Search in sources :

Example 11 with VcenterObjectConnectionException

use of com.emc.storageos.vcentercontroller.exceptions.VcenterObjectConnectionException in project coprhd-controller by CoprHD.

the class VcenterApiClient method refreshRescanHostStorage.

public void refreshRescanHostStorage(String datacenterName, String clusterNameOrMoRef, String hostname) throws VcenterSystemException, VcenterObjectNotFoundException, VcenterObjectConnectionException {
    try {
        _log.info("Request to check connected and powered on for host " + hostname + " in datacenter " + datacenterName + " cluster " + clusterNameOrMoRef);
        HostSystem hostSystem = (HostSystem) createManagedEntityMap(datacenterName, clusterNameOrMoRef, hostname, true).get("HostSystem");
        _log.info("Refresh and rescan storage before disk discovery on host " + hostname);
        // expensive but needed to pickup any storage changes
        hostSystem.getHostStorageSystem().rescanAllHba();
        _log.info("Rescan HBAs complete");
        hostSystem.getHostStorageSystem().refreshStorageSystem();
        _log.info("Refresh storage system complete");
    } catch (VcenterSystemException | VcenterObjectNotFoundException | VcenterObjectConnectionException e) {
        throw e;
    } catch (Exception e) {
        _log.error("refreshRescanStorage exception " + e);
        throw new VcenterSystemException(e.getLocalizedMessage());
    }
}
Also used : VcenterObjectNotFoundException(com.emc.storageos.vcentercontroller.exceptions.VcenterObjectNotFoundException) VcenterObjectConnectionException(com.emc.storageos.vcentercontroller.exceptions.VcenterObjectConnectionException) HostSystem(com.vmware.vim25.mo.HostSystem) VcenterSystemException(com.emc.storageos.vcentercontroller.exceptions.VcenterSystemException) VcenterSystemException(com.emc.storageos.vcentercontroller.exceptions.VcenterSystemException) VcenterServerConnectionException(com.emc.storageos.vcentercontroller.exceptions.VcenterServerConnectionException) VcenterObjectConnectionException(com.emc.storageos.vcentercontroller.exceptions.VcenterObjectConnectionException) VcenterObjectNotFoundException(com.emc.storageos.vcentercontroller.exceptions.VcenterObjectNotFoundException)

Example 12 with VcenterObjectConnectionException

use of com.emc.storageos.vcentercontroller.exceptions.VcenterObjectConnectionException in project coprhd-controller by CoprHD.

the class VcenterApiClient method removeHost.

public void removeHost(String datacenterName, String clusterNameOrMoRef, String hostname) throws VcenterSystemException, VcenterObjectNotFoundException, VcenterObjectConnectionException {
    try {
        _log.info("Request to remove host " + hostname + " to datacenter " + datacenterName + " cluster " + clusterNameOrMoRef);
        ClusterComputeResource clusterComputeResource = (ClusterComputeResource) createManagedEntityMap(datacenterName, clusterNameOrMoRef, null, false).get("ClusterComputeResource");
        HostSystem hostSystem = findByHostname(clusterComputeResource, hostname);
        if (hostSystem == null) {
            _log.info("Host not found thus no delete necessary");
        } else {
            // Check that host can be removed (either in maintenance mode or in a !poweredOn or !connected state
            try {
                checkHostConnectedPoweredOn(hostSystem);
                _log.info("Host " + hostname + " connected and powered on so now check maintenance mode");
                if (!hostSystem.getRuntime().isInMaintenanceMode()) {
                    _log.error("Host " + hostname + " must be in maintenance mode before deletion");
                    throw new VcenterSystemException("Host " + hostname + " must be in maintenance mode before deletion");
                }
            } catch (VcenterObjectConnectionException e) {
                _log.info("Host is not connected and/or powered on so go ahead and remove without maintenance mode check");
            }
            // Remove
            Integer hostOperationTimeout = Integer.parseInt(propertyInfo.getProperty("vcenter_host_operation_timeout"));
            VcenterTaskMonitor taskMonitor = new VcenterTaskMonitor(hostOperationTimeout);
            Task deleteHostTask = hostSystem.destroy_Task();
            // call blocks
            VcenterTaskMonitor.TaskStatus taskStatus = taskMonitor.monitor(deleteHostTask);
            if (taskStatus == VcenterTaskMonitor.TaskStatus.SUCCESS) {
                _log.info("Delete host " + hostname + " task succeeded");
            } else if (taskStatus == VcenterTaskMonitor.TaskStatus.ERROR) {
                String errorMessage = "Delete host " + hostname + " task failed - " + taskMonitor.errorDescription;
                _log.error(errorMessage);
                throw new VcenterSystemException(errorMessage);
            } else if (taskStatus == VcenterTaskMonitor.TaskStatus.TIMED_OUT) {
                _log.error("Delete host " + hostname + " task timed out at " + taskMonitor.progressPercent);
                throw new VcenterSystemException("Delete host " + hostname + " task timed out at " + taskMonitor.progressPercent);
            } else {
                // Should not execute - Just here in case someone ever added a new state so we catch it
                _log.error("Unknown task status encountered tracking delete host " + taskStatus);
                throw new VcenterSystemException("Unknown task status encountered tracking delete host " + taskStatus);
            }
        }
    } catch (VcenterSystemException | VcenterObjectNotFoundException | VcenterObjectConnectionException e) {
        throw e;
    } catch (Exception e) {
        _log.error("Exception removing host: " + e);
        throw new VcenterSystemException(e.getLocalizedMessage());
    }
}
Also used : Task(com.vmware.vim25.mo.Task) VcenterObjectNotFoundException(com.emc.storageos.vcentercontroller.exceptions.VcenterObjectNotFoundException) ClusterComputeResource(com.vmware.vim25.mo.ClusterComputeResource) VcenterObjectConnectionException(com.emc.storageos.vcentercontroller.exceptions.VcenterObjectConnectionException) HostSystem(com.vmware.vim25.mo.HostSystem) VcenterSystemException(com.emc.storageos.vcentercontroller.exceptions.VcenterSystemException) VcenterSystemException(com.emc.storageos.vcentercontroller.exceptions.VcenterSystemException) VcenterServerConnectionException(com.emc.storageos.vcentercontroller.exceptions.VcenterServerConnectionException) VcenterObjectConnectionException(com.emc.storageos.vcentercontroller.exceptions.VcenterObjectConnectionException) VcenterObjectNotFoundException(com.emc.storageos.vcentercontroller.exceptions.VcenterObjectNotFoundException)

Example 13 with VcenterObjectConnectionException

use of com.emc.storageos.vcentercontroller.exceptions.VcenterObjectConnectionException in project coprhd-controller by CoprHD.

the class VcenterApiClient method addHost.

public String addHost(String datacenterName, String clusterNameOrMoRef, String hostname, String username, String password) throws VcenterSystemException, VcenterObjectNotFoundException, VcenterObjectConnectionException {
    try {
        _log.info("Request to add host " + hostname + " to datacenter " + datacenterName + " cluster " + clusterNameOrMoRef);
        ClusterComputeResource clusterComputeResource = (ClusterComputeResource) createManagedEntityMap(datacenterName, clusterNameOrMoRef, null, false).get("ClusterComputeResource");
        HostSystem hostSystem = findByHostname(clusterComputeResource, hostname);
        if (hostSystem == null) {
            _log.info("Host " + hostname + " does not exist and will be added");
            if (username == null || username.trim().equals("") || password == null || password.trim().equals("")) {
                _log.error("Username and/or password missing - Both required to add host to cluster");
                throw new VcenterSystemException("Username and/or password missing - Both required to add host to cluster");
            }
            HostConnectSpec hostConnectSpec = new HostConnectSpec();
            hostConnectSpec.setHostName(hostname);
            hostConnectSpec.setUserName(username);
            hostConnectSpec.setPassword(password);
            // ie
            hostConnectSpec.setSslThumbprint(getHostCertificate(hostname, username, password));
            // 1D:0C:63:FC:58:58:1C:66:F0:5B:C4:0B:F3:84:0E:27:E9:59:83:F7
            _log.info("Attempt to add host " + hostname + " to " + datacenterName + "/" + clusterComputeResource.getName());
            Integer hostOperationTimeout = Integer.parseInt(propertyInfo.getProperty("vcenter_host_operation_timeout"));
            Integer hostOperationTimeoutMillis = hostOperationTimeout * 1000;
            Integer retryCount = 1;
            Long startTimeMillis = System.currentTimeMillis();
            Long cutoffTimeMillis = startTimeMillis + hostOperationTimeoutMillis;
            VcenterTaskMonitor taskMonitor = new VcenterTaskMonitor(hostOperationTimeout);
            Task addHostTask = clusterComputeResource.addHost_Task(hostConnectSpec, true, null, null);
            // call blocks
            VcenterTaskMonitor.TaskStatus taskStatus = taskMonitor.monitor(addHostTask);
            while ((System.currentTimeMillis() < cutoffTimeMillis) && taskStatus == VcenterTaskMonitor.TaskStatus.ERROR) {
                _log.info("Add host " + hostname + " retry error " + taskMonitor.errorDescription + " count " + retryCount);
                // Retry is time based and if each retry executes very quickly (ie milliseconds) then we should
                Thread.sleep(60000);
                // throttle and only retry every 60 seconds
                addHostTask = clusterComputeResource.addHost_Task(hostConnectSpec, true, null, null);
                // call blocks
                taskStatus = taskMonitor.monitor(addHostTask);
                retryCount++;
            }
            if (taskStatus == VcenterTaskMonitor.TaskStatus.SUCCESS) {
                _log.info("Add host " + hostname + " task succeeded - Attempt to find host in cluster");
                hostSystem = findByHostname(clusterComputeResource, hostname);
            } else if (taskStatus == VcenterTaskMonitor.TaskStatus.ERROR) {
                String errorMessage = "Add host " + hostname + " task failed - " + taskMonitor.errorDescription;
                if (taskMonitor.errorDescription.contains("already exists.")) {
                    errorMessage += " - Ensure adding host to correct cluster or remove host from its existing cluster";
                }
                _log.error(errorMessage);
                throw new VcenterSystemException(errorMessage);
            } else if (taskStatus == VcenterTaskMonitor.TaskStatus.TIMED_OUT) {
                _log.error("Add host " + hostname + " task timed out at " + taskMonitor.progressPercent);
                throw new VcenterSystemException("Add host " + hostname + " task timed out at " + taskMonitor.progressPercent);
            } else {
                // Should not execute - Just here in case someone ever added a new state so we catch it
                _log.error("Unknown task status encountered tracking add host " + taskStatus);
                throw new VcenterSystemException("Unknown task status encountered tracking add host " + taskStatus);
            }
            trackHostTasks(hostSystem, hostOperationTimeout);
            // Only take host out of maintenance mode if it's being added. We don't want to exit maintenance mode on other hosts since
            // customer may have intentionally put it on that.
            exitMaintenanceModeHost(hostSystem);
        }
        // Some nice conveniences to reconnect and exit maintenance mode to ready the host for action
        reconnectHost(hostSystem);
        // Collect some details
        StringBuffer hostDetails = new StringBuffer();
        hostDetails.append("Host ").append(datacenterName).append("/").append(clusterComputeResource.getName()).append("/").append(hostname).append(" ");
        String os = hostSystem.getPropertyByPath("config.product.version").toString();
        hostDetails.append("OS ").append(os).append(" ");
        String key = hostSystem.getMOR().getVal();
        hostDetails.append("key ").append(key).append(" ");
        String connectionState = hostSystem.getRuntime().getConnectionState().toString();
        hostDetails.append("Connection State ").append(connectionState).append(" ");
        String powerState = hostSystem.getRuntime().getPowerState().toString();
        hostDetails.append("Power State ").append(powerState).append(" ");
        boolean maintenanceMode = hostSystem.getRuntime().isInMaintenanceMode();
        hostDetails.append("Maintenance Mode ").append(maintenanceMode).append(" ");
        _log.info(hostDetails.toString());
        return hostSystem.getMOR().getVal();
    } catch (VcenterSystemException | VcenterObjectNotFoundException | VcenterObjectConnectionException e) {
        throw e;
    } catch (Exception e) {
        _log.error("Exception adding host: " + e);
        throw new VcenterSystemException(e.getLocalizedMessage());
    }
}
Also used : Task(com.vmware.vim25.mo.Task) ClusterComputeResource(com.vmware.vim25.mo.ClusterComputeResource) VcenterObjectConnectionException(com.emc.storageos.vcentercontroller.exceptions.VcenterObjectConnectionException) VcenterSystemException(com.emc.storageos.vcentercontroller.exceptions.VcenterSystemException) VcenterServerConnectionException(com.emc.storageos.vcentercontroller.exceptions.VcenterServerConnectionException) VcenterObjectConnectionException(com.emc.storageos.vcentercontroller.exceptions.VcenterObjectConnectionException) VcenterObjectNotFoundException(com.emc.storageos.vcentercontroller.exceptions.VcenterObjectNotFoundException) VcenterObjectNotFoundException(com.emc.storageos.vcentercontroller.exceptions.VcenterObjectNotFoundException) HostSystem(com.vmware.vim25.mo.HostSystem) HostConnectSpec(com.vmware.vim25.HostConnectSpec) VcenterSystemException(com.emc.storageos.vcentercontroller.exceptions.VcenterSystemException)

Example 14 with VcenterObjectConnectionException

use of com.emc.storageos.vcentercontroller.exceptions.VcenterObjectConnectionException in project coprhd-controller by CoprHD.

the class VcenterApiClient method getHostCertificate.

private String getHostCertificate(String hostname, String username, String password) throws VcenterSystemException, VcenterObjectConnectionException {
    try {
        Integer hostOperationTimeout = Integer.parseInt(propertyInfo.getProperty("vcenter_host_operation_timeout"));
        Integer sslTimeout = hostOperationTimeout * 1000;
        Integer retryCount = 1;
        Long startTimeMillis = System.currentTimeMillis();
        Long cutoffTimeMillis = startTimeMillis + sslTimeout;
        VcenterHostCertificateGetter.HostConnectionStatus status = VcenterHostCertificateGetter.getInstance().getConnectionStatus(hostname, 443, "/host/ssl_cert", username, password, 300);
        while ((System.currentTimeMillis() < cutoffTimeMillis) && status == VcenterHostCertificateGetter.HostConnectionStatus.UNREACHABLE) {
            _log.info("Host " + hostname + " is unreachable after attempt " + retryCount + " - Retry SSL cert request");
            // Retry is time based and if each retry executes very quickly (ie milliseconds) then we should
            Thread.sleep(10000);
            // throttle and only retry every 10 seconds
            status = VcenterHostCertificateGetter.getInstance().getConnectionStatus(hostname, 443, "/host/ssl_cert", username, password, 300);
            retryCount++;
        }
        String errorSuggestion = null;
        if (status == VcenterHostCertificateGetter.HostConnectionStatus.UNREACHABLE) {
            errorSuggestion = "Ensure host is powered on and responsive. Can be caused by intermittent or temporary connectivity issue thus retry recommended";
        } else if (status == VcenterHostCertificateGetter.HostConnectionStatus.UNKNOWN) {
            errorSuggestion = "Ensure hostname is correct and DNS resolvable";
        } else if (status == VcenterHostCertificateGetter.HostConnectionStatus.UNAUTHORIZED) {
            errorSuggestion = "Ensure host credentials are correct";
        }
        if (errorSuggestion != null) {
            _log.error("Host " + hostname + " not reachable in state " + status + " - " + errorSuggestion);
            throw new VcenterObjectConnectionException("Host " + hostname + " not reachable in state " + status + " - " + errorSuggestion);
        }
        String thumbprint = null;
        try {
            thumbprint = VcenterHostCertificateGetter.getInstance().getSSLThumbprint(hostname, 443, "/host/ssl_cert", username, password, sslTimeout);
        } catch (Exception e) {
            _log.info("Error getting host " + hostname + " SSL certificate " + e);
            thumbprint = VcenterHostCertificateGetter.getInstance().getSSLThumbprint(hostname, 443, "/host/ssl_cert", username, password, sslTimeout);
        }
        if (thumbprint == null || thumbprint.equals("")) {
            _log.error("Could not retrieve host " + hostname + " SSL certificate");
            throw new VcenterSystemException("Could not retrieve host " + hostname + " SSL certificate");
        }
        return thumbprint;
    } catch (VcenterSystemException | VcenterObjectConnectionException e) {
        throw e;
    } catch (Exception e) {
        _log.error("getHostCertificate exception " + e);
        throw new VcenterSystemException(e.getLocalizedMessage());
    }
}
Also used : VcenterObjectConnectionException(com.emc.storageos.vcentercontroller.exceptions.VcenterObjectConnectionException) VcenterSystemException(com.emc.storageos.vcentercontroller.exceptions.VcenterSystemException) VcenterServerConnectionException(com.emc.storageos.vcentercontroller.exceptions.VcenterServerConnectionException) VcenterObjectConnectionException(com.emc.storageos.vcentercontroller.exceptions.VcenterObjectConnectionException) VcenterObjectNotFoundException(com.emc.storageos.vcentercontroller.exceptions.VcenterObjectNotFoundException) VcenterSystemException(com.emc.storageos.vcentercontroller.exceptions.VcenterSystemException)

Example 15 with VcenterObjectConnectionException

use of com.emc.storageos.vcentercontroller.exceptions.VcenterObjectConnectionException in project coprhd-controller by CoprHD.

the class VcenterControllerImpl method enterMaintenanceMode.

@Override
public void enterMaintenanceMode(URI datacenterUri, URI clusterUri, URI hostUri) throws InternalException {
    VcenterApiClient vcenterApiClient = null;
    try {
        Host host = _dbClient.queryObject(Host.class, hostUri);
        VcenterDataCenter vcenterDataCenter = _dbClient.queryObject(VcenterDataCenter.class, datacenterUri);
        Cluster cluster = _dbClient.queryObject(Cluster.class, clusterUri);
        Vcenter vcenter = _dbClient.queryObject(Vcenter.class, vcenterDataCenter.getVcenter());
        _log.info("Request to enter maintenance mode for " + vcenter.getLabel() + "/" + vcenterDataCenter.getLabel() + "/" + cluster.getLabel() + "/" + host.getHostName());
        vcenterApiClient = new VcenterApiClient(_coordinator.getPropertyInfo());
        vcenterApiClient.setup(vcenter.getIpAddress(), vcenter.getUsername(), vcenter.getPassword(), vcenter.getPortNumber());
        vcenterApiClient.enterMaintenanceMode(vcenterDataCenter.getLabel(), cluster.getExternalId(), host.getHostName());
    } catch (VcenterObjectConnectionException e) {
        throw VcenterControllerException.exceptions.objectConnectionException(e.getLocalizedMessage(), e);
    } catch (VcenterObjectNotFoundException e) {
        throw VcenterControllerException.exceptions.objectNotFoundException(e.getLocalizedMessage(), e);
    } catch (VcenterServerConnectionException e) {
        throw VcenterControllerException.exceptions.serverConnectionException(e.getLocalizedMessage(), e);
    } catch (Exception e) {
        _log.error("enterMaintenanceMode exception " + e);
        throw VcenterControllerException.exceptions.unexpectedException(e.getLocalizedMessage(), e);
    } finally {
        if (vcenterApiClient != null) {
            vcenterApiClient.destroy();
        }
    }
}
Also used : Vcenter(com.emc.storageos.db.client.model.Vcenter) VcenterServerConnectionException(com.emc.storageos.vcentercontroller.exceptions.VcenterServerConnectionException) VcenterObjectNotFoundException(com.emc.storageos.vcentercontroller.exceptions.VcenterObjectNotFoundException) VcenterApiClient(com.emc.storageos.vcentercontroller.VcenterApiClient) VcenterObjectConnectionException(com.emc.storageos.vcentercontroller.exceptions.VcenterObjectConnectionException) Cluster(com.emc.storageos.db.client.model.Cluster) Host(com.emc.storageos.db.client.model.Host) VcenterDataCenter(com.emc.storageos.db.client.model.VcenterDataCenter) VcenterServerConnectionException(com.emc.storageos.vcentercontroller.exceptions.VcenterServerConnectionException) InternalException(com.emc.storageos.svcs.errorhandling.resources.InternalException) VcenterObjectConnectionException(com.emc.storageos.vcentercontroller.exceptions.VcenterObjectConnectionException) DeviceControllerException(com.emc.storageos.exceptions.DeviceControllerException) VcenterObjectNotFoundException(com.emc.storageos.vcentercontroller.exceptions.VcenterObjectNotFoundException) VcenterControllerException(com.emc.storageos.vcentercontroller.exceptions.VcenterControllerException)

Aggregations

VcenterObjectConnectionException (com.emc.storageos.vcentercontroller.exceptions.VcenterObjectConnectionException)17 VcenterObjectNotFoundException (com.emc.storageos.vcentercontroller.exceptions.VcenterObjectNotFoundException)17 VcenterServerConnectionException (com.emc.storageos.vcentercontroller.exceptions.VcenterServerConnectionException)15 VcenterSystemException (com.emc.storageos.vcentercontroller.exceptions.VcenterSystemException)11 HostSystem (com.vmware.vim25.mo.HostSystem)7 InternalException (com.emc.storageos.svcs.errorhandling.resources.InternalException)6 VcenterControllerException (com.emc.storageos.vcentercontroller.exceptions.VcenterControllerException)6 Host (com.emc.storageos.db.client.model.Host)5 Cluster (com.emc.storageos.db.client.model.Cluster)4 Vcenter (com.emc.storageos.db.client.model.Vcenter)4 VcenterDataCenter (com.emc.storageos.db.client.model.VcenterDataCenter)4 DeviceControllerException (com.emc.storageos.exceptions.DeviceControllerException)4 VcenterApiClient (com.emc.storageos.vcentercontroller.VcenterApiClient)4 ClusterComputeResource (com.vmware.vim25.mo.ClusterComputeResource)4 Task (com.vmware.vim25.mo.Task)3 ComputeSystemControllerException (com.emc.storageos.computesystemcontroller.exceptions.ComputeSystemControllerException)2 ImageServerControllerException (com.emc.storageos.imageservercontroller.exceptions.ImageServerControllerException)2 ServiceCoded (com.emc.storageos.svcs.errorhandling.model.ServiceCoded)2 HostScsiDisk (com.vmware.vim25.HostScsiDisk)2 HostStorageDeviceInfo (com.vmware.vim25.HostStorageDeviceInfo)2