Search in sources :

Example 31 with VcenterDataCenter

use of com.emc.storageos.db.client.model.VcenterDataCenter in project coprhd-controller by CoprHD.

the class HostService method validateHostData.

/**
 * Validates the create/update host input data
 *
 * @param hostParam
 *            the input parameter
 * @param host
 *            the host being updated in case of update operation.
 *            This parameter must be null for create operations.n
 */
protected void validateHostData(HostParam hostParam, URI tenanUri, Host host, Boolean validateConnection) {
    Cluster cluster = null;
    VcenterDataCenter dataCenter = null;
    Project project = null;
    Volume volume = null;
    // validate the host type
    if (hostParam.getType() != null) {
        ArgValidator.checkFieldValueFromEnum(hostParam.getType(), "Type", Host.HostType.class);
    }
    // validate the project is present, active, and in the same tenant org
    if (!NullColumnValueGetter.isNullURI(hostParam.getProject())) {
        project = queryObject(Project.class, hostParam.getProject(), true);
        if (!project.getTenantOrg().getURI().equals(tenanUri)) {
            throw APIException.badRequests.resourcedoesNotBelongToHostTenantOrg("project");
        }
    }
    if (!NullColumnValueGetter.isNullURI(hostParam.getBootVolume())) {
        volume = queryObject(Volume.class, hostParam.getBootVolume(), true);
        if (!volume.getTenant().getURI().equals(tenanUri)) {
            throw APIException.badRequests.resourcedoesNotBelongToHostTenantOrg("boot volume");
        }
    }
    // validate the cluster is present, active, and in the same tenant org
    if (!NullColumnValueGetter.isNullURI(hostParam.getCluster())) {
        cluster = queryObject(Cluster.class, hostParam.getCluster(), true);
        if (!cluster.getTenant().equals(tenanUri)) {
            throw APIException.badRequests.resourcedoesNotBelongToHostTenantOrg("cluster");
        }
    }
    // validate the data center is present, active, and in the same tenant org
    if (!NullColumnValueGetter.isNullURI(hostParam.getVcenterDataCenter())) {
        dataCenter = queryObject(VcenterDataCenter.class, hostParam.getVcenterDataCenter(), true);
        if (!dataCenter.getTenant().equals(tenanUri)) {
            throw APIException.badRequests.resourcedoesNotBelongToHostTenantOrg("data center");
        }
    }
    if (cluster != null) {
        if (dataCenter != null) {
            // check the cluster and data center are consistent
            if (!dataCenter.getId().equals(cluster.getVcenterDataCenter())) {
                throw APIException.badRequests.invalidParameterClusterNotInDataCenter(cluster.getLabel(), dataCenter.getLabel());
            }
        } else if (project != null) {
            // check the cluster and data center are consistent
            if (!project.getId().equals(cluster.getProject())) {
                throw APIException.badRequests.invalidParameterClusterNotInHostProject(cluster.getLabel());
            }
        }
    }
    // check the host name is not a duplicate
    if (host == null || (hostParam.getHostName() != null && !hostParam.getHostName().equals(host.getHostName()))) {
        checkDuplicateAltId(Host.class, "hostName", EndpointUtility.changeCase(hostParam.getHostName()), "host");
    }
    // check the host label is not a duplicate
    if (host == null || (hostParam.getName() != null && !hostParam.getName().equals(host.getLabel()))) {
        checkDuplicateLabel(Host.class, hostParam.getName());
    }
    // If the host project is being changed, check for active exports
    if (host != null && !areEqual(host.getProject(), hostParam.getProject())) {
        if (ComputeSystemHelper.isHostInUse(_dbClient, host.getId())) {
            throw APIException.badRequests.hostProjectChangeNotAllowed(host.getHostName());
        }
    }
    // Find out if the host should be discoverable by checking input and current values
    Boolean discoverable = hostParam.getDiscoverable() == null ? (host == null ? Boolean.FALSE : host.getDiscoverable()) : hostParam.getDiscoverable();
    boolean vCenterManaged = host == null ? false : Host.HostType.Esx.name().equals(host.getType()) && !NullColumnValueGetter.isNullURI(host.getVcenterDataCenter());
    // If discoverable, ensure username and password are set in the current host or parameters
    if (!vCenterManaged && discoverable != null && discoverable) {
        String username = hostParam.getUserName() == null ? (host == null ? null : host.getUsername()) : hostParam.getUserName();
        String password = hostParam.getPassword() == null ? (host == null ? null : host.getPassword()) : hostParam.getPassword();
        ArgValidator.checkFieldNotNull(username, "username");
        ArgValidator.checkFieldNotNull(password, "password");
        Host.HostType hostType = Host.HostType.valueOf(hostParam.getType() == null ? (host == null ? null : host.getType()) : hostParam.getType());
        if (hostType != null && hostType == Host.HostType.Windows) {
            Integer portNumber = hostParam.getPortNumber() == null ? (host == null ? null : host.getPortNumber()) : hostParam.getPortNumber();
            ArgValidator.checkFieldNotNull(portNumber, "port_number");
        }
    }
    if (validateConnection != null && validateConnection == true) {
        if (!HostConnectionValidator.isHostConnectionValid(hostParam, host)) {
            throw APIException.badRequests.invalidHostConnection();
        }
    }
}
Also used : Project(com.emc.storageos.db.client.model.Project) UnManagedVolume(com.emc.storageos.db.client.model.UnManagedDiscoveredObjects.UnManagedVolume) Volume(com.emc.storageos.db.client.model.Volume) Cluster(com.emc.storageos.db.client.model.Cluster) VcenterDataCenter(com.emc.storageos.db.client.model.VcenterDataCenter) Host(com.emc.storageos.db.client.model.Host)

Example 32 with VcenterDataCenter

use of com.emc.storageos.db.client.model.VcenterDataCenter in project coprhd-controller by CoprHD.

the class ComputeDeviceControllerImpl method addStepsVcenterClusterCleanup.

/**
 * A cluster could have only discovered hosts, only provisioned hosts, or mixed.
 * If cluster has only provisioned hosts, then the hosts will be deleted from vCenter.
 * If cluster has only discovered hosts, then the hosts will not be deleted from vCenter.
 * If cluster is mixed, then the hosts will not be deleted from the vCenter; however, the
 * provisioned hosts will still be decommissioned, and their state in vCenter will be "disconnected".
 * If a cluster is provisioned or mixed, then check VMs step will be executed since hosts with running
 * VMs may endup decommissioned.
 */
@Override
public String addStepsVcenterClusterCleanup(Workflow workflow, String waitFor, URI clusterId, boolean deactivateCluster) throws InternalException {
    Cluster cluster = _dbClient.queryObject(Cluster.class, clusterId);
    if (null == cluster) {
        log.info("Could not find cluster instance for cluster having id {}", clusterId.toString());
        return waitFor;
    }
    if (NullColumnValueGetter.isNullURI(cluster.getVcenterDataCenter())) {
        log.info("cluster is not synced to vcenter");
        return waitFor;
    }
    List<URI> clusterHosts = ComputeSystemHelper.getChildrenUris(_dbClient, clusterId, Host.class, "cluster");
    // Before we get to this cluster removal, ClusterService has a precheck to verify the matching environments
    if (deactivateCluster && (null == clusterHosts || clusterHosts.isEmpty())) {
        VcenterDataCenter vcenterDataCenter = _dbClient.queryObject(VcenterDataCenter.class, cluster.getVcenterDataCenter());
        log.info("Cluster has no hosts, removing empty cluster : {}, from vCenter : {}", cluster.getLabel(), vcenterDataCenter.getLabel());
        waitFor = workflow.createStep(REMOVE_VCENTER_CLUSTER, "If synced with vCenter, remove the cluster", waitFor, clusterId, clusterId.toString(), this.getClass(), new Workflow.Method("removeVcenterCluster", cluster.getId(), cluster.getVcenterDataCenter()), null, null);
        return waitFor;
    }
    boolean hasDiscoveredHosts = false;
    boolean hasProvisionedHosts = false;
    List<Host> hosts = _dbClient.queryObject(Host.class, clusterHosts);
    for (Host host : hosts) {
        if (NullColumnValueGetter.isNullURI(host.getComputeElement())) {
            hasDiscoveredHosts = true;
        } else {
            hasProvisionedHosts = true;
        }
    }
    log.info("cluster has provisioned hosts: {}, and discovered hosts: {}", hasProvisionedHosts, hasDiscoveredHosts);
    /*
         * Check for VMs only if the cluster was provisioned or is mixed.
         */
    if (hasProvisionedHosts) {
        waitFor = workflow.createStep(CHECK_CLUSTER_VMS, "If synced with vCenter, check if there are VMs in the cluster", waitFor, clusterId, clusterId.toString(), this.getClass(), new Workflow.Method("checkClusterVms", cluster.getId(), cluster.getVcenterDataCenter()), new Workflow.Method(ROLLBACK_NOTHING_METHOD), null);
    }
    /*
         * Remove cluster from vcenter only if all hosts are provisioned.
         */
    if (hasProvisionedHosts && !hasDiscoveredHosts && deactivateCluster) {
        waitFor = workflow.createStep(REMOVE_VCENTER_CLUSTER, "If synced with vCenter, remove the cluster", waitFor, clusterId, clusterId.toString(), this.getClass(), new Workflow.Method("removeVcenterCluster", cluster.getId(), cluster.getVcenterDataCenter()), new Workflow.Method(ROLLBACK_NOTHING_METHOD), null);
    }
    return waitFor;
}
Also used : Cluster(com.emc.storageos.db.client.model.Cluster) VcenterDataCenter(com.emc.storageos.db.client.model.VcenterDataCenter) Host(com.emc.storageos.db.client.model.Host) URI(java.net.URI)

Example 33 with VcenterDataCenter

use of com.emc.storageos.db.client.model.VcenterDataCenter in project coprhd-controller by CoprHD.

the class HostRescanDeviceController method getRescanAdapter.

private HostRescanAdapter getRescanAdapter(Host host) {
    if (HostType.Linux.name().equalsIgnoreCase(host.getType())) {
        return new LinuxSystemCLI(host.getHostName(), host.getPortNumber(), host.getUsername(), host.getPassword());
    } else if (HostType.AIX.name().equalsIgnoreCase(host.getType())) {
        return new AixSystem(host.getHostName(), host.getPortNumber(), host.getUsername(), host.getPassword());
    } else if (HostType.HPUX.name().equalsIgnoreCase(host.getType())) {
        return new HpuxSystem(host.getHostName(), host.getPortNumber(), host.getUsername(), host.getPassword());
    } else if (HostType.Windows.name().equalsIgnoreCase(host.getType())) {
        List<AuthnProvider> authProviders = new ArrayList<AuthnProvider>();
        for (URI authProviderId : getDbClient().queryByType(AuthnProvider.class, true)) {
            AuthnProvider authProvider = getDbClient().queryObject(AuthnProvider.class, authProviderId);
            authProviders.add(authProvider);
        }
        KerberosUtil.initializeKerberos(authProviders);
        return WindowsHostDiscoveryAdapter.createWindowsSystem(host);
    } else if (HostType.Esx.name().equalsIgnoreCase(host.getType())) {
        if (host.getUsername() != null && host.getPassword() != null) {
            VCenterAPI vcenterAPI = EsxHostDiscoveryAdapter.createVCenterAPI(host);
            List<HostSystem> hostSystems = vcenterAPI.listAllHostSystems();
            if (hostSystems != null && !hostSystems.isEmpty()) {
                return new HostStorageAPI(hostSystems.get(0));
            } else {
                return null;
            }
        } else if (host.getVcenterDataCenter() != null) {
            // Lookup the vcenter datacenter and vcenter to retreive the HostSystem
            VcenterDataCenter dataCenter = dbClient.queryObject(VcenterDataCenter.class, host.getVcenterDataCenter());
            if (dataCenter == null || dataCenter.getInactive()) {
                throw DeviceControllerException.exceptions.objectNotFound(host.getVcenterDataCenter());
            }
            Vcenter vcenter = dbClient.queryObject(Vcenter.class, dataCenter.getVcenter());
            if (vcenter == null || vcenter.getInactive()) {
                throw DeviceControllerException.exceptions.objectNotFound(dataCenter.getVcenter());
            }
            VCenterAPI vCenterAPI = VcenterDiscoveryAdapter.createVCenterAPI(vcenter);
            String datacenterName = dataCenter.getLabel();
            HostSystem hostSystem = vCenterAPI.findHostSystem(datacenterName, host.getHostName());
            if (hostSystem != null) {
                return new HostStorageAPI(hostSystem);
            } else {
                return null;
            }
        }
    } else {
        // Unanticipated host type
        return null;
    }
    return null;
}
Also used : VCenterAPI(com.iwave.ext.vmware.VCenterAPI) LinuxSystemCLI(com.iwave.ext.linux.LinuxSystemCLI) Vcenter(com.emc.storageos.db.client.model.Vcenter) AuthnProvider(com.emc.storageos.db.client.model.AuthnProvider) URI(java.net.URI) HpuxSystem(com.emc.hpux.HpuxSystem) AixSystem(com.emc.aix.AixSystem) HostSystem(com.vmware.vim25.mo.HostSystem) ArrayList(java.util.ArrayList) List(java.util.List) VcenterDataCenter(com.emc.storageos.db.client.model.VcenterDataCenter) HostStorageAPI(com.iwave.ext.vmware.HostStorageAPI)

Example 34 with VcenterDataCenter

use of com.emc.storageos.db.client.model.VcenterDataCenter in project coprhd-controller by CoprHD.

the class ActionableEventExecutor method hostDatacenterChangeDetails.

/**
 * Get details for the hostDatacenterChange method
 * NOTE: In order to maintain backwards compatibility, do not change the signature of this method.
 *
 * @param hostId the host that is moving datacenters
 * @param clusterId the cluster the host is moving to
 * @param datacenterId the datacenter the host is moving to
 * @param isVcenter if true, vcenter api operations will be executed against the host to detach/unmount and attach/mount disks and
 *            datastores
 * @return list of event details
 */
// Invoked using reflection for the event framework
@SuppressWarnings("unused")
public List<String> hostDatacenterChangeDetails(URI hostId, URI clusterId, URI datacenterId, boolean isVcenter) {
    List<String> result = Lists.newArrayList();
    Host host = _dbClient.queryObject(Host.class, hostId);
    VcenterDataCenter datacenter = _dbClient.queryObject(VcenterDataCenter.class, datacenterId);
    if (host != null && datacenter != null) {
        result.add(ComputeSystemDialogProperties.getMessage("ComputeSystem.hostDatacenterChangeDetails", host.getLabel(), datacenter.getLabel()));
        result.addAll(hostClusterChangeDetails(hostId, clusterId, datacenterId, isVcenter));
    }
    return result;
}
Also used : Host(com.emc.storageos.db.client.model.Host) VcenterDataCenter(com.emc.storageos.db.client.model.VcenterDataCenter)

Example 35 with VcenterDataCenter

use of com.emc.storageos.db.client.model.VcenterDataCenter in project coprhd-controller by CoprHD.

the class ClusterService method validateVcenterClusterHosts.

/**
 * Validate that the hosts in the cluster in our database matches the vCenter environment
 *
 * @param cluster the cluster to check
 */
public void validateVcenterClusterHosts(Cluster cluster) {
    if (null == cluster) {
        _log.error("Validation cluster is not set, not performing vCenter cluster validation");
        return;
    }
    // We can only proceed if this cluster belongs to a datacenter
    if (NullColumnValueGetter.isNullURI(cluster.getVcenterDataCenter())) {
        _log.info("Cluster is not synced to vcenter");
        return;
    }
    // Get a list of the cluster's hosts that are in our database.
    List<URI> clusterHosts = ComputeSystemHelper.getChildrenUris(_dbClient, cluster.getId(), Host.class, "cluster");
    VcenterDataCenter vcenterDataCenter = _dbClient.queryObject(VcenterDataCenter.class, cluster.getVcenterDataCenter());
    // If the datacenter is not in our database, we must fail the validation.
    if (vcenterDataCenter == null) {
        throw APIException.badRequests.vCenterDataCenterNotFound(cluster.getVcenterDataCenter());
    }
    // If the datacenter has a null vCenter reference, we must fail the validation.
    if (NullColumnValueGetter.isNullURI(vcenterDataCenter.getVcenter())) {
        throw APIException.badRequests.vCenterDataCenterHasNullVcenter(vcenterDataCenter.forDisplay());
    }
    Vcenter vcenter = _dbClient.queryObject(Vcenter.class, vcenterDataCenter.getVcenter());
    // If the vCenter is not in our database, we must fail the validation.
    if (vcenter == null) {
        throw APIException.badRequests.vCenterNotFound(vcenterDataCenter.getVcenter());
    }
    List<Host> dbHosts = _dbClient.queryObject(Host.class, clusterHosts);
    VCenterAPI api = VcenterDiscoveryAdapter.createVCenterAPI(vcenter);
    try {
        // Query the vCenter to get a reference to the cluster so that we can compare the hosts between the actual
        // environment and our database representation of the cluster.
        ClusterComputeResource vcenterCluster = api.findCluster(vcenterDataCenter.getLabel(), cluster.getLabel());
        // The cluster may not have been pushed to vCenter yet.
        if (vcenterCluster == null) {
            _log.info("Unable to find cluster %s in datacenter %s in vCenter environment %s", cluster.getLabel(), vcenterDataCenter.getLabel(), vcenter.getLabel());
            return;
        }
        // Gather a set of all the host UUIDs in this vCenter cluster.
        Set<String> vCenterHostUuids = Sets.newHashSet();
        for (HostSystem hostSystem : vcenterCluster.getHosts()) {
            if (hostSystem != null && hostSystem.getHardware() != null && hostSystem.getHardware().systemInfo != null) {
                vCenterHostUuids.add(hostSystem.getHardware().systemInfo.uuid);
            }
        }
        // Gather a set of all the host UUIDs in our database.
        Set<String> dbHostUuids = Sets.newHashSet();
        for (Host host : dbHosts) {
            dbHostUuids.add(host.getUuid());
        }
        // If there are hosts in vCenter that are not in our database, fail the validation
        if (!dbHostUuids.containsAll(vCenterHostUuids)) {
            throw APIException.badRequests.clusterHostMismatch(cluster.forDisplay());
        }
    } finally {
        if (api != null) {
            api.logout();
        }
    }
}
Also used : VCenterAPI(com.iwave.ext.vmware.VCenterAPI) Vcenter(com.emc.storageos.db.client.model.Vcenter) ClusterComputeResource(com.vmware.vim25.mo.ClusterComputeResource) HostSystem(com.vmware.vim25.mo.HostSystem) VcenterDataCenter(com.emc.storageos.db.client.model.VcenterDataCenter) Host(com.emc.storageos.db.client.model.Host) URI(java.net.URI)

Aggregations

VcenterDataCenter (com.emc.storageos.db.client.model.VcenterDataCenter)40 Host (com.emc.storageos.db.client.model.Host)27 Vcenter (com.emc.storageos.db.client.model.Vcenter)25 Cluster (com.emc.storageos.db.client.model.Cluster)19 DeviceControllerException (com.emc.storageos.exceptions.DeviceControllerException)15 InternalException (com.emc.storageos.svcs.errorhandling.resources.InternalException)15 URI (java.net.URI)12 VcenterControllerException (com.emc.storageos.vcentercontroller.exceptions.VcenterControllerException)11 VcenterObjectConnectionException (com.emc.storageos.vcentercontroller.exceptions.VcenterObjectConnectionException)11 VcenterObjectNotFoundException (com.emc.storageos.vcentercontroller.exceptions.VcenterObjectNotFoundException)11 VcenterServerConnectionException (com.emc.storageos.vcentercontroller.exceptions.VcenterServerConnectionException)11 VcenterApiClient (com.emc.storageos.vcentercontroller.VcenterApiClient)10 HostSystem (com.vmware.vim25.mo.HostSystem)9 VCenterAPI (com.iwave.ext.vmware.VCenterAPI)7 GetVcenterDataCenter (com.emc.sa.service.vmware.tasks.GetVcenterDataCenter)4 ComputeSystemControllerException (com.emc.storageos.computesystemcontroller.exceptions.ComputeSystemControllerException)4 CoordinatorException (com.emc.storageos.coordinator.exceptions.CoordinatorException)4 ClientControllerException (com.emc.storageos.exceptions.ClientControllerException)4 APIException (com.emc.storageos.svcs.errorhandling.resources.APIException)4 ControllerException (com.emc.storageos.volumecontroller.ControllerException)4