Package com.vmware.bdd.clone.spec

Examples of com.vmware.bdd.clone.spec.VmCreateSpec


      logger.info("syncCreateVMs, start to create VMs.");

      // update vm info in vc cache, in case snapshot is removed by others
      VcVmUtil.updateVm(templateVm.getId());

      VmCreateSpec sourceSpec = new VmCreateSpec();
      sourceSpec.setVmId(templateVm.getId());
      sourceSpec.setVmName(templateVm.getName());
      sourceSpec.setTargetHost(templateVm.getHost());

      List<VmCreateSpec> specs = new ArrayList<VmCreateSpec>();
      Map<String, BaseNode> nodeMap = new HashMap<String, BaseNode>();
      for (BaseNode vNode : vNodes) {
         // prepare for cloning result
         nodeMap.put(vNode.getVmName(), vNode);
         vNode.setSuccess(false);
         vNode.setFinished(false);
         // generate create spec for fast clone
         VmCreateSpec spec = new VmCreateSpec();
         VmSchema createSchema = getVmSchema(vNode);
         spec.setSchema(createSchema);
         String defaultPgName = null;
         GuestMachineIdSpec machineIdSpec =
               new GuestMachineIdSpec(networkAdds,
                     vNode.fetchPortGroupToIpV4Map(),
                     vNode.getPrimaryMgtPgName());
         logger.info("machine id of vm " + vNode.getVmName() + ":\n"
               + machineIdSpec.toString());
         spec.setBootupConfigs(machineIdSpec.toGuestVariable());
         // timeout is 10 mintues
         StartVmPostPowerOn query =
               new StartVmPostPowerOn(vNode.getNics().keySet(),
                     Constants.VM_POWER_ON_WAITING_SEC);
         spec.setPostPowerOn(query);
         spec.setPrePowerOn(getPrePowerOnFunc(vNode, reserveRawDisks));
         spec.setLinkedClone(false);
         spec.setTargetDs(getVcDatastore(vNode));
         spec.setTargetFolder(folders.get(vNode.getGroupName()));
         spec.setTargetHost(VcResourceUtils.findHost(vNode.getTargetHost()));
         spec.setTargetRp(getVcResourcePool(vNode, clusterRpName));
         spec.setVmName(vNode.getVmName());
         specs.add(spec);
      }

      BaseProgressCallback callback = new BaseProgressCallback(statusUpdator);

      logger.info("ClusteringService, start to clone template.");
      AuAssert.check(specs.size() > 0);
      VmSchema vmSchema = specs.get(0).getSchema();
      VcVmUtil.checkAndCreateSnapshot(vmSchema);

      // call clone service to copy templates
      List<VmCreateResult<?>> results =
            cloneService.createCopies(sourceSpec, cloneConcurrency, specs,
                  callback);
      if (results == null || results.isEmpty()) {
         for (VmCreateSpec spec : specs) {
            BaseNode node = nodeMap.get(spec.getVmName());
            node.setFinished(true);
            node.setSuccess(false);
         }
         return false;
      }
      boolean success = true;
      int total = 0;
      for (VmCreateResult<?> result : results) {
         VmCreateSpec spec = (VmCreateSpec) result.getSpec();
         BaseNode node = nodeMap.get(spec.getVmName());
         node.setVmMobId(spec.getVmId());
         node.setSuccess(true);
         node.setFinished(true);
         boolean vmSucc = VcVmUtil.setBaseNodeForVm(node, spec.getVmId());
         if (!vmSucc || !result.isSuccess()) {
            success = false;
            node.setSuccess(false);
            if (result.getErrMessage() != null) {
               node.setErrMessage(result.getErrTimestamp() + " "
View Full Code Here


      // mock clone service
      int i = 0;
      List<VmCreateResult<?>> nodes = new ArrayList<VmCreateResult<?>>();
      for (BaseNode n : vNodes) {
         VmCreateResult<VmCreateSpec> s = new VmCreateResult<VmCreateSpec>();
         s.setSpec(new VmCreateSpec());
         s.getSpec().setVmName(n.getVmName());
         s.getSpec().setVmId("vm" + i);
         s.setSuccess(true);
         nodes.add(s);
      }
View Full Code Here

      }
   }

   private static void setReturnVM(CreateVmSP sp) {
      try {
         VmCreateSpec spec = Mockito.mock(VmCreateSpec.class);
         Mockito.when(spec.getVmName()).thenReturn("cluster-worker-0");
         Mockito.when(spec.getVmId()).thenReturn("create-vm-succ");
         Field field = sp.getClass().getDeclaredField("targetVmSpec");
         field.setAccessible(true);
         field.set(sp, spec);
      } catch (Exception e) {
         logger.error("set return value failed.", e);
View Full Code Here

         ProgressCallback callback) {
      Pair<Callable<Void>, Callable<Void>>[] storeProcedures =
            new Pair[consumers.size()];

      for (int i = 0; i < consumers.size(); i++) {
         VmCreateSpec consumer = consumers.get(i);
         CreateVmSP cloneVmSp =
               new CreateVmSP(consumer.getVmName(), consumer.getSchema(),
                     consumer.getTargetRp(), consumer.getTargetDs(),
                     consumer.getPrePowerOn(), consumer.getPostPowerOn(),
                     consumer.getBootupConfigs(), false,
                     consumer.getTargetFolder(), consumer.getTargetHost());
         CompensateCreateVmSP deleteVmSp = new CompensateCreateVmSP(cloneVmSp);
         storeProcedures[i] =
               new Pair<Callable<Void>, Callable<Void>>(cloneVmSp, deleteVmSp);
      }

      try {
         // execute store procedures to create VMs
         logger.info("ClusterCloneService, start to create vms.");
         Pair<ExecutionResult, ExecutionResult>[] result =
               Scheduler
                     .executeStoredProcedures(
                           com.vmware.aurora.composition.concurrent.Priority.BACKGROUND,
                           storeProcedures, storeProcedures.length, callback);
         if (result == null) {
            logger.error("No VM is created.");
            return null;
         }

         int total = 0;
         List<VmCreateResult<?>> cloned = new ArrayList<VmCreateResult<?>>();
         for (int i = 0; i < storeProcedures.length; i++) {
            Pair<ExecutionResult, ExecutionResult> pair = result[i];
            VmCreateResult<VmCreateSpec> createResult = new VmCreateResult<VmCreateSpec>();
            VmCreateSpec node = consumers.get(i);
            createResult.setSpec(node);
            CreateVmSP sp = (CreateVmSP) storeProcedures[i].first;
            if (sp.getVM() != null) {
               node.setVmId(sp.getVM().getId());
            }
            if (pair.first.finished && pair.first.throwable == null
                  && pair.second.finished == false) {
               ++total;
               createResult.setSuccess(true);
            } else if (pair.first.throwable != null) {
               createResult.setSuccess(false);
               processException(createResult, pair.first.throwable);
               logger.error("Failed to create VM " + node.getVmName(),
                     pair.first.throwable);
            }
            cloned.add(createResult);
         }
         logger.info(total + " VMs are successfully created.");
View Full Code Here

TOP

Related Classes of com.vmware.bdd.clone.spec.VmCreateSpec

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.