Exemplo n.º 1
0
 @Override
 public void injectColumnsDetails(Stat statObj, DbClient client) throws Exception {
   ProtectionSystem protectionObj =
       client.queryObject(ProtectionSystem.class, statObj.getResourceId());
   // Given a protection system, find a volume protected by this protection system,
   // and then extract the project and vpool
   Volume protectedVolume = null;
   URIQueryResultList resultList = new URIQueryResultList();
   client.queryByConstraint(
       ContainmentConstraint.Factory.getProtectionSystemVolumesConstraint(protectionObj.getId()),
       resultList);
   for (Iterator<URI> volumeItr = resultList.iterator(); volumeItr.hasNext(); ) {
     Volume volume = client.queryObject(Volume.class, volumeItr.next());
     if (volume.getProtectionController().equals(protectionObj.getId())) {
       protectedVolume = volume;
       break;
     }
   }
   if (protectedVolume != null) {
     _logger.info(
         "Found volume "
             + protectedVolume.getWWN()
             + " protected by this protection controller.  Get the Cos/Project/Tenant.");
     statObj.setProject(protectedVolume.getProject().getURI());
     statObj.setVirtualPool(protectedVolume.getVirtualPool());
     statObj.setTenant(protectedVolume.getTenant().getURI());
   } else {
     statObj.setProject(null);
     statObj.setVirtualPool(null);
     statObj.setTenant(null);
     throw new SMIPluginException(
         "Cassandra Database Insertion Error.  Cannot identify Project/CoS/Tenant for ProtectionSystem",
         -1);
   }
 }
  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());
      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();
    }
  }