Package com.vmware.aurora.vc

Examples of com.vmware.aurora.vc.VcVirtualMachine


      VcResourcePool rp = VcVmUtil.getTargetRp(clusterName, groupName, node);

      String recoverVmName = node.getVmName() + RECOVERY_VM_NAME_POSTFIX;
      if (node.getMoId() != null) {
         VcVirtualMachine vm = VcCache.getIgnoreMissing(node.getMoId());
         // the vm id is null if the vm is removed
         if (vm == null) {
            throw ClusterHealServiceException.ERROR_STATUS(nodeName,
                  "Serengeti and VC are inconsistent as vm " + nodeName
                        + " is recorded in Seregeti, but not found in VC.");
         }

         VcVirtualMachine recoverVm = VcVmUtil.findVmInRp(rp, recoverVmName);
         if (recoverVm != null) {
            try {
               VcVmUtil.destroyVm(recoverVm.getId(), false);
            } catch (Exception e) {
               logger.error("failed to remove obsolete recovery vm for node "
                     + nodeName);
               throw ClusterHealServiceException
                     .FAILED_DELETE_VM(recoverVmName);
            }
         }

         return null;
      } else {
         VcVirtualMachine oldVm = VcVmUtil.findVmInRp(rp, nodeName);
         VcVirtualMachine recoverVm = VcVmUtil.findVmInRp(rp, recoverVmName);

         if (oldVm != null && recoverVm != null) {
            logger.error("vm " + oldVm.getId() + " and recover vm "
                  + recoverVm.getId() + " both exist, this is not expected!.");
            throw ClusterHealServiceException.ERROR_STATUS(nodeName, "vm "
                  + nodeName + " and its recovery vm " + recoverVmName
                  + " both exist, remove the one you created manually!");
         } else if (oldVm == null && recoverVm == null) {
            logger.error("original vm and recover vm for node " + nodeName
                  + " both missed, this is not expected!.");
            throw ClusterHealServiceException.ERROR_STATUS(nodeName, "vm "
                  + nodeName + " and its recovery vm " + recoverVmName
                  + " both missed, it's not expected!");
         } else if (recoverVm != null) {
            logger.info("recover vm " + recoverVm.getId()
                  + " exists, rename it to " + nodeName);
            VcVmUtil.rename(recoverVm.getId(), nodeName);
            return recoverVm;
         } else {
            logger.info("recovery probably failed at power on last time, simply return vm "
                  + oldVm.getId());
            return oldVm;
View Full Code Here


               }
               return false;
            }
            case VmDisconnected:
            case VmConnected: {
               VcVirtualMachine vm = VcCache.getIgnoreMissing(moRef);
               if (vm == null) {
                  return false;
               }
               vm.update();
               break;
            }
            case VmResourcePoolMoved: {
               VmResourcePoolMovedEvent event = (VmResourcePoolMovedEvent) e;
               VcCache.refresh(event.getOldParent().getResourcePool());
               VcCache.refresh(event.getNewParent().getResourcePool());
               break;
            }
            case VmCreated: {
               VmCreatedEvent event = (VmCreatedEvent) e;
               VcVirtualMachine vm = VcCache.get(event.getVm().getVm());
               vm.refreshRP();
               break;
            }
            case HostRemoved: {
               logger.info("Host removed event received" + e);
            }
View Full Code Here

   }

   private static BaseNode convertNode(ClusterCreate cluster,
         NodeGroupCreate group, NodeEntity entity) {
      logger.debug("convert node " + entity.getVmName());
      VcVirtualMachine vcVm = null;
      if (entity.getMoId() != null) {
         vcVm = VcCache.getIgnoreMissing(entity.getMoId());
      }
      BaseNode node = new BaseNode(entity.getVmName());
      node.setTargetHost(entity.getHostName());
View Full Code Here

      for (BaseNode node : existingNodes) {
         if (node.getVmMobId() == null) {
            deletedNodes.add(node);
            continue;
         }
         VcVirtualMachine vm = VcCache.getIgnoreMissing(node.getVmMobId());
         if (vm == null || (!vm.isPoweredOn())
               || !VcVmUtil.checkIpAddresses(vm)) {
            deletedNodes.add(node);
            continue;
         }
         String haFlag = node.getNodeGroup().getHaFlag();
         if (haFlag != null
               && Constants.HA_FLAG_FT.equals(haFlag.toLowerCase())) {
            if (!VcVmUtil.verifyFTState(vm)) {
               logger.info("FT secondary VM state incorrect for node "
                     + vm.getName() + ", " + "FT state " + vm.getFTState()
                     + " is unexpected.");
               deletedNodes.add(node);
               continue;
            }
         }
View Full Code Here

                  + node.getVmName()
                  + " cannot be controlled through VC. Remove it from VC manually, and then repeat the operarion.");
            throw ClusteringServiceException.VM_UNAVAILABLE(node.getVmName());
         }
         // verify from VC
         VcVirtualMachine vm = VcCache.getIgnoreMissing(node.getMoId());

         if (expectedStatus == NodeStatus.VM_READY) {

            if (vm == null || (!vm.isPoweredOn())) {
               throw ClusteringServiceException.VM_STATUS_ERROR(node
                     .getStatus().toString(), expectedStatus.toString());
            }

            if (!VcVmUtil.checkIpAddresses(vm)) {
               // throw out clear information
               throw ClusteringServiceException.CANNOT_GET_IP_ADDRESS(node
                     .getVmName());
            }
            String haFlag = node.getNodeGroup().getHaFlag();
            if (haFlag != null
                  && Constants.HA_FLAG_FT.equals(haFlag.toLowerCase())) {
               if (!VcVmUtil.verifyFTState(vm)) {
                  logger.info("FT secondary VM state incorrect for node "
                        + vm.getName() + ", " + "FT state " + vm.getFTState()
                        + " is unexpected.");
                  throw ClusteringServiceException.ENABLE_FT_FAILED(null,
                        node.getVmName());
               }
            }
         } else {
            if (vm == null || (!vm.isPoweredOff())) {
               throw ClusteringServiceException.VM_STATUS_ERROR(node
                     .getStatus().toString(), expectedStatus.toString());
            }
         }
      }
View Full Code Here

   private Void callInternal() {
      if (vmId == null) {
         return null;
      }
      VcVirtualMachine vm = VcCache.getIgnoreMissing(vmId);
      if (vm == null) {
         throw BddException.NOT_FOUND("Virtual Machine", vmId);
      }
      Map<String, String> variables = vm.getGuestVariables();
      String status = variables.get(Constants.VM_DISK_FORMAT_STATUS_KEY);
      try {
         long start = System.currentTimeMillis();
         long timeout = maxWaitingSeconds * 1000;
         while ((status == null
               || status.equalsIgnoreCase(DISK_FORMAT_INPROGRESS))
               && System.currentTimeMillis() - start < timeout) {
            Thread.sleep(QUERY_GUEST_VARIABLE_INTERVAL);
            variables = vm.getGuestVariables();
            status = variables.get(Constants.VM_DISK_FORMAT_STATUS_KEY);
         }
      } catch (InterruptedException e) {
         logger.info("Waiting disk format thread is interrupted.", e);
      }
      if (status == null
            || status.equalsIgnoreCase(DISK_FORMAT_INPROGRESS)) {
         logger.error("Didn't get disk format finished signal for vm "
               + vm.getName() + ".");
         throw SoftwareManagementException.GET_DISK_FORMAT_STATUS_ERROR(vm.getName());
      }
      if (!status.equalsIgnoreCase(DISK_FORMAT_SUCCESS)) {
         variables = vm.getGuestVariables();
         String error = variables.get(Constants.VM_DISK_FORMAT_ERROR_KEY);
         logger.error("Failed to format disk for vm " + vm.getName() + ", for " + error);
         throw SoftwareManagementException.FAILED_TO_FORMAT_DISK(vm.getName(), error);
      }
      logger.info("Disk format finished for vm " + vm.getName());
      return null;
   }
View Full Code Here

   public static void checkVmFTAndCpuNumber(final String vmId, final String vmName,
         final int cpuNumber) {
      Boolean ftEnabled = VcContext.inVcSessionDo(new VcSession<Boolean>() {
         @Override
         protected Boolean body() throws Exception {
            final VcVirtualMachine vcVm = VcCache.getIgnoreMissing(vmId);
            if (vcVm == null) {
               logger.info("vm: " + vmId + " is not found.");
               return false;
            }
            FaultToleranceState ftState = vcVm.getFTState();
            if (FaultToleranceState.notConfigured.ordinal() == ftState
                  .ordinal()) {
               return false;
            }
            return true;
View Full Code Here

      }
   }

   public static void checkVmMaxConfiguration(final String vmId,
         final int cpuNumber, final long memory) {
      final VcVirtualMachine vcVm = VcCache.getIgnoreMissing(vmId);
      int hardwareVersion = 0;
      if (vcVm == null) {
         logger.info("vm: " + vmId + " is not found.");
         hardwareVersion = -1;
      } else {
         hardwareVersion = VcContext.inVcSessionDo(new VcSession<Integer>() {
            @Override
            protected Integer body() throws Exception {
               VirtualMachine vimVm = vcVm.getManagedObject();
               EnvironmentBrowser envBrowser =
                     MoUtil.getManagedObject(vimVm.getEnvironmentBrowser());
               ConfigOption configOption =
                     envBrowser.queryConfigOption(null, null);
               int hardwareVersion =
                     configOption.getHardwareOptions().getHwVersion();
               logger.info("hardware version is: " + hardwareVersion);
               return hardwareVersion;
            }
         });
      }
      compareMaxConfiguration(vcVm.getName(), hardwareVersion, cpuNumber,
            memory);
   }
View Full Code Here

            Configuration.getString(Constants.SERENGETI_SERVER_VM_MOBID);
      if (serverMobId == null) {
         logger.warn("Server MobId (" + Constants.SERENGETI_SERVER_VM_MOBID + ") is missing.");
         return "";
      }
      VcVirtualMachine serverVm = VcCache.get(serverMobId);
      if (serverVm != null)
         return serverVm.getHost().getName();
      else
         return "";
   }
View Full Code Here

      String serverMobId =
            Configuration.getString(Constants.SERENGETI_SERVER_VM_MOBID);
      if (serverMobId == null) {
         throw ClusteringServiceException.TEMPLATE_ID_NOT_FOUND();
      }
      VcVirtualMachine serverVm = VcCache.get(serverMobId);

      if (ConfigInfo.isDeployAsVApp()) {
         VcResourcePool vApp = serverVm.getParentVApp();
         initUUID(vApp.getName());
         for (VcVirtualMachine vm : vApp.getChildVMs()) {
            // assume only two vm under serengeti vApp, serengeti server and
            // template
            if (!vm.getName().equals(serverVm.getName())) {
               logger.info("got template vm: " + vm.getName());
               return vm;
            }
         }
         return null;
View Full Code Here

TOP

Related Classes of com.vmware.aurora.vc.VcVirtualMachine

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.