use of com.emc.storageos.db.client.model.Vcenter in project coprhd-controller by CoprHD.
the class VcenterControllerImpl method vcenterClusterCreateDatastoreOperation.
public void vcenterClusterCreateDatastoreOperation(URI vcenterId, URI vcenterDataCenterId, URI clusterId, URI volumeId, String selectHostStepId, String stepId) {
VcenterApiClient vcenterApiClient = null;
try {
WorkflowStepCompleter.stepExecuting(stepId);
URI hostId = (URI) _workflowService.loadStepData(selectHostStepId);
if (hostId == null) {
_log.error("Workflow loadStepData on " + selectHostStepId + " is null");
throw new Exception("Workflow loadStepData on " + selectHostStepId + " is null");
}
VcenterDataCenter vcenterDataCenter = _dbClient.queryObject(VcenterDataCenter.class, vcenterDataCenterId);
Cluster cluster = _dbClient.queryObject(Cluster.class, clusterId);
Vcenter vcenter = _dbClient.queryObject(Vcenter.class, vcenterId);
Host host = _dbClient.queryObject(Host.class, hostId);
Volume volume = _dbClient.queryObject(Volume.class, volumeId);
vcenterApiClient = new VcenterApiClient(_coordinator.getPropertyInfo());
vcenterApiClient.setup(vcenter.getIpAddress(), vcenter.getUsername(), vcenter.getPassword(), vcenter.getPortNumber());
String key = vcenterApiClient.createDatastore(vcenterDataCenter.getLabel(), cluster.getExternalId(), host.getHostName(), volume.getWWN(), volume.getLabel());
_log.info("Successfully created or located datastore " + volume.getLabel() + " " + key);
host.setVcenterDataCenter(vcenterDataCenter.getId());
_dbClient.updateAndReindexObject(host);
WorkflowStepCompleter.stepSucceded(stepId);
} catch (Exception e) {
_log.error("vcenterClusterCreateDatastoreOperation exception " + e);
WorkflowStepCompleter.stepFailed(stepId, VcenterControllerException.exceptions.hostException(e.getLocalizedMessage(), e));
} finally {
if (vcenterApiClient != null) {
vcenterApiClient.destroy();
}
}
}
use of com.emc.storageos.db.client.model.Vcenter in project coprhd-controller by CoprHD.
the class DataCollectionJobScheduler method isDataCollectionJobSchedulingNeeded.
/**
* @param <T>
* @param system
* @param scheduler indicates if the job is initiated automatically by scheduler or if it is
* requested by a user.
* @return
*/
private <T extends DiscoveredSystemObject> boolean isDataCollectionJobSchedulingNeeded(T system, DataCollectionJob job) {
String type = job.getType();
boolean scheduler = job.isSchedulerJob();
String namespace = job.getNamespace();
// COP-20052 if an unmanaged CG discovery is requested, just run it
if (!scheduler && (Discovery_Namespaces.UNMANAGED_VOLUMES.name().equalsIgnoreCase(namespace) || Discovery_Namespaces.BLOCK_SNAPSHOTS.name().equalsIgnoreCase(namespace) || Discovery_Namespaces.UNMANAGED_FILESYSTEMS.name().equalsIgnoreCase(namespace) || Discovery_Namespaces.UNMANAGED_CGS.name().equalsIgnoreCase(namespace))) {
_logger.info(namespace + " discovery has been requested by the user, scheduling now...");
return true;
}
if (ControllerServiceImpl.METERING.equalsIgnoreCase(type) && !DiscoveredDataObject.RegistrationStatus.REGISTERED.toString().equalsIgnoreCase(system.getRegistrationStatus())) {
return false;
}
// Scan triggered the discovery of this new System found, and discovery was in progress
// in the mean time, UI triggered the discovery again, the last Run time will be 0
// as we depend on the last run time to calculate next run time, the value will be
// always 3600 seconds in this case, which is lower than the maximum idle interval which is 4200 sec.
// hence a new Job will again get rescheduled.
// This fix, calculates next time from last Run time , only if its not 0.
long lastTime = getLastRunTime(system, type);
long nextTime = getNextRunTime(system, type);
if (lastTime > 0) {
nextTime = lastTime + JobIntervals.get(type).getInterval() * 1000;
}
if (ControllerServiceImpl.DISCOVERY.equalsIgnoreCase(type) && system instanceof NetworkSystem) {
type = ControllerServiceImpl.NS_DISCOVERY;
}
if (ControllerServiceImpl.DISCOVERY.equalsIgnoreCase(type) && system instanceof ComputeSystem) {
type = ControllerServiceImpl.COMPUTE_DISCOVERY;
}
if (ControllerServiceImpl.DISCOVERY.equalsIgnoreCase(type) && (system instanceof Host || system instanceof Vcenter)) {
type = ControllerServiceImpl.CS_DISCOVERY;
}
// check directly on the queue to determine if the job is in progress
boolean inProgress = ControllerServiceImpl.isDataCollectionJobInProgress(job);
boolean queued = ControllerServiceImpl.isDataCollectionJobQueued(job);
if (!queued && !inProgress) {
// the job does not appear on the queue in either active or queued state
// check the storage system database status; if it shows that it's scheduled or in progress, something
// went wrong with a previous discovery. Set it to error and allow it to be rescheduled.
boolean dbInProgressStatus = isInProgress(system, type);
if (dbInProgressStatus) {
_logger.warn(type + " job for " + system.getLabel() + " is not queued or in progress; correcting the ViPR DB status");
updateDataCollectionStatus(system, type, DiscoveredDataObject.DataCollectionJobStatus.ERROR);
}
// check for any pending tasks; if there are any, they're orphaned and should be cleaned up
// look for tasks older than one hour; this will exclude the discovery job currently being scheduled
Calendar oneHourAgo = Calendar.getInstance();
oneHourAgo.setTime(Date.from(LocalDateTime.now().minusDays(1).atZone(ZoneId.systemDefault()).toInstant()));
if (ControllerServiceImpl.DISCOVERY.equalsIgnoreCase(type)) {
TaskUtils.cleanupPendingTasks(_dbClient, system.getId(), ResourceOperationTypeEnum.DISCOVER_STORAGE_SYSTEM.getName(), URI.create(SYSTEM_TENANT_ID), oneHourAgo);
} else if (ControllerServiceImpl.METERING.equalsIgnoreCase(type)) {
TaskUtils.cleanupPendingTasks(_dbClient, system.getId(), ResourceOperationTypeEnum.METERING_STORAGE_SYSTEM.getName(), URI.create(SYSTEM_TENANT_ID), oneHourAgo);
}
} else {
// log a message if the discovery job has been runnig for longer than expected
long currentTime = System.currentTimeMillis();
long maxIdleTime = JobIntervals.getMaxIdleInterval() * 1000;
long jobInterval = JobIntervals.get(job.getType()).getInterval();
// next time is the time the job was picked up from the queue plus the job interval
// so the start time of the currently running job is next time minus job interval
// the running time of the currently running job is current time - next time - job interval
boolean longRunningDiscovery = inProgress && (currentTime - nextTime - jobInterval >= maxIdleTime);
if (longRunningDiscovery) {
_logger.warn(type + " job for " + system.getLabel() + " has been running for longer than expected; this could indicate a problem with the storage system");
}
}
return isJobSchedulingNeeded(system.getId(), type, (queued || inProgress), isError(system, type), scheduler, lastTime, nextTime);
}
use of com.emc.storageos.db.client.model.Vcenter 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;
}
use of com.emc.storageos.db.client.model.Vcenter in project coprhd-controller by CoprHD.
the class VcenterDiscoveryAdapter method checkDuplicateVcenter.
protected void checkDuplicateVcenter(Vcenter vcenter, String nativeGuid) {
if (nativeGuid != null && !nativeGuid.isEmpty()) {
for (Vcenter existingVcenter : modelClient.vcenters().findByNativeGuid(nativeGuid, true)) {
if (!existingVcenter.getId().equals(vcenter.getId())) {
ComputeSystemControllerException ex = ComputeSystemControllerException.exceptions.duplicateSystem("vCenter", existingVcenter.getLabel());
DiscoveryStatusUtils.markAsFailed(modelClient, vcenter, ex.getMessage(), ex);
throw ex;
}
}
}
}
use of com.emc.storageos.db.client.model.Vcenter in project coprhd-controller by CoprHD.
the class ComputeSystemControllerImpl method unmountAndDetach.
/**
* Unmounts and detaches every datastore and disk associated with the volumes in the export group.
* For each volume in the export group, the backed datastore is unmounted and the associated disk is detached from
* the host.
*
* @param exportGroupId
* export group that contains volumes
* @param hostId
* host to attach and mount to
* @param vcenterId
* vcenter that the host belongs to
* @param vcenterDatacenter
* vcenter datacenter that the host belongs to
* @param stepId
* the id of the workflow step
*/
public void unmountAndDetach(URI exportGroupId, URI hostId, URI vCenterId, URI vcenterDatacenter, String stepId) {
WorkflowStepCompleter.stepExecuting(stepId);
try {
Host esxHost = _dbClient.queryObject(Host.class, hostId);
Vcenter vCenter = _dbClient.queryObject(Vcenter.class, vCenterId);
VcenterDataCenter vCenterDataCenter = _dbClient.queryObject(VcenterDataCenter.class, vcenterDatacenter);
ExportGroup exportGroup = _dbClient.queryObject(ExportGroup.class, exportGroupId);
VCenterAPI api = VcenterDiscoveryAdapter.createVCenterAPI(vCenter);
HostSystem hostSystem = api.findHostSystem(vCenterDataCenter.getLabel(), esxHost.getLabel());
if (hostSystem == null) {
_log.info("Not able to find host " + esxHost.getLabel() + " in vCenter. Unable to validate");
WorkflowStepCompleter.stepSucceded(stepId);
return;
}
HostStorageAPI storageAPI = new HostStorageAPI(hostSystem);
Map<String, Datastore> wwnDatastores = getWwnDatastoreMap(hostSystem);
if (exportGroup != null && exportGroup.getVolumes() != null) {
for (String volume : exportGroup.getVolumes().keySet()) {
BlockObject blockObject = BlockObject.fetch(_dbClient, URI.create(volume));
if (blockObject != null) {
Datastore datastore = getDatastoreByWwn(wwnDatastores, blockObject.getWWN());
if (datastore != null) {
if (VMwareUtils.isDatastoreMountedOnHost(datastore, hostSystem)) {
boolean storageIOControlEnabled = datastore.getIormConfiguration().isEnabled();
if (storageIOControlEnabled) {
setStorageIOControl(api, datastore, false);
}
_log.info("Unmount datastore " + datastore.getName() + " from host " + esxHost.getLabel());
storageAPI.unmountVmfsDatastore(datastore);
if (storageIOControlEnabled) {
setStorageIOControl(api, datastore, true);
}
} else {
_log.info("Datastore " + datastore.getName() + " is not mounted on host " + esxHost.getLabel() + ". Skipping unmounting of datastore.");
}
}
}
// VBDU TODO: COP-28459, If datastore doesn't match, why do we need to run DetachSCSILun() ?
// Test mechanism to invoke a failure. No-op on production systems.
InvokeTestFailure.internalOnlyInvokeTestFailure(InvokeTestFailure.ARTIFICIAL_FAILURE_030);
for (HostScsiDisk entry : storageAPI.listScsiDisks()) {
if (VolumeWWNUtils.wwnMatches(VMwareUtils.getDiskWwn(entry), blockObject.getWWN())) {
if (!VMwareUtils.isDiskOff(entry)) {
_log.info("Detach SCSI Lun " + entry.getCanonicalName() + " from host " + esxHost.getLabel());
storageAPI.detachScsiLun(entry);
} else {
_log.info("SCSI Lun " + entry.getCanonicalName() + " is not in a valid state to detach");
}
}
}
storageAPI.refreshStorage();
// Test mechanism to invoke a failure. No-op on production systems.
InvokeTestFailure.internalOnlyInvokeTestFailure(InvokeTestFailure.ARTIFICIAL_FAILURE_031);
}
}
WorkflowStepCompleter.stepSucceded(stepId);
} catch (Exception ex) {
_log.error(ex.getMessage(), ex);
WorkflowStepCompleter.stepFailed(stepId, DeviceControllerException.errors.jobFailed(ex));
}
}
Aggregations