Examples of VMTemplateHostVO


Examples of com.cloud.storage.VMTemplateHostVO

     * Tempalte is not bound to pxeserver right now, and we assume the pxeserver
     * cannot be removed once it was added. so we use host id of first found pxe
     * server as reference in template_host_ref.
     * This maybe a FIXME in future.
     */
    VMTemplateHostVO vmTemplateHost = null;
    if (zoneId == null || zoneId == -1) {
      List<DataCenterVO> dcs = _dcDao.listAllIncludingRemoved();
      for (DataCenterVO dc : dcs) {
        HostVO pxe = _resourceMgr.listAllHostsInOneZoneByType(Host.Type.PxeServer, dc.getId()).get(0);

        vmTemplateHost = _tmpltHostDao.findByHostTemplate(dc.getId(), template.getId());
        if (vmTemplateHost == null) {
          vmTemplateHost = new VMTemplateHostVO(pxe.getId(), template.getId(), new Date(), 100,
              Status.DOWNLOADED, null, null, null, null, template.getUrl());
          _tmpltHostDao.persist(vmTemplateHost);
          templateCreateUsage(template, pxe);
        }
      }
    } else {
      HostVO pxe = _resourceMgr.listAllHostsInOneZoneByType(Host.Type.PxeServer, zoneId).get(0);
      vmTemplateHost = new VMTemplateHostVO(pxe.getId(), template.getId(), new Date(), 100,
          Status.DOWNLOADED, null, null, null, null, template.getUrl());
      _tmpltHostDao.persist(vmTemplateHost);
      templateCreateUsage(template, pxe);
    }
   
View Full Code Here

Examples of com.cloud.storage.VMTemplateHostVO

      Account account = _accountDao.findByIdIncludingRemoved(template.getAccountId());
      String eventType = EventTypes.EVENT_TEMPLATE_DELETE;
      List<VMTemplateHostVO> templateHostVOs = _tmpltHostDao.listByTemplateId(templateId);
     
    for (VMTemplateHostVO vo : templateHostVOs) {
      VMTemplateHostVO lock = null;
      try {
        HostVO pxeServer = _hostDao.findById(vo.getHostId());
        if (!isAllZone && pxeServer.getDataCenterId() != profile.getZoneId()) {
          continue;
        }

        lock = _tmpltHostDao.acquireInLockTable(vo.getId());
        if (lock == null) {
          s_logger.debug("Failed to acquire lock when deleting templateHostVO with ID: " + vo.getId());
          success = false;
          break;
        }

        vo.setDestroyed(true);
        _tmpltHostDao.update(vo.getId(), vo);
        VMTemplateZoneVO templateZone = _tmpltZoneDao.findByZoneTemplate(pxeServer.getDataCenterId(), templateId);
        if (templateZone != null) {
          _tmpltZoneDao.remove(templateZone.getId());
        }

        UsageEventVO usageEvent = new UsageEventVO(eventType, account.getId(), pxeServer.getDataCenterId(), templateId, null);
        _usageEventDao.persist(usageEvent);
      } finally {
        if (lock != null) {
          _tmpltHostDao.releaseFromLockTable(lock.getId());
        }
      }
    }
     
      s_logger.debug("Successfully marked template host refs for template: " + template.getName() + " as destroyed in zone: " + zoneName);
 
      // If there are no more non-destroyed template host entries for this template, delete it
    if (success && (_tmpltHostDao.listByTemplateId(templateId).size() == 0)) {
      long accountId = template.getAccountId();
     
      VMTemplateVO lock = _tmpltDao.acquireInLockTable(templateId);

      try {
        if (lock == null) {
          s_logger.debug("Failed to acquire lock when deleting template with ID: " + templateId);
          success = false;
        } else if (_tmpltDao.remove(templateId)) {
          // Decrement the number of templates
            _resourceLimitMgr.decrementResourceCount(accountId, ResourceType.template);
        }

      } finally {
        if (lock != null) {
          _tmpltDao.releaseFromLockTable(lock.getId());
        }
      }
      s_logger.debug("Removed template: " + template.getName() + " because all of its template host refs were marked as destroyed.");
    }
   
View Full Code Here

Examples of com.cloud.storage.VMTemplateHostVO

                privateTemplate.setChecksum(checkSum);
                _templateDao.update(templateId, privateTemplate);

                // add template zone ref for this template
                _templateDao.addTemplateToZone(privateTemplate, zoneId);
                VMTemplateHostVO templateHostVO = new VMTemplateHostVO(secondaryStorageHost.getId(), templateId);
                templateHostVO.setDownloadPercent(100);
                templateHostVO.setDownloadState(Status.DOWNLOADED);
                templateHostVO.setInstallPath(answer.getPath());
                templateHostVO.setLastUpdated(new Date());
                templateHostVO.setSize(answer.getVirtualSize());
                templateHostVO.setPhysicalSize(answer.getphysicalSize());
                _templateHostDao.persist(templateHostVO);

                UsageEventVO usageEvent = new UsageEventVO(EventTypes.EVENT_TEMPLATE_CREATE, privateTemplate.getAccountId(), secondaryStorageHost.getDataCenterId(), privateTemplate.getId(),
                        privateTemplate.getName(), null, privateTemplate.getSourceTemplateId(), templateHostVO.getSize());
                _usageEventDao.persist(usageEvent);
                txn.commit();
            }
        } finally {
            if (snapshot != null && snapshot.getSwiftId() != null && secondaryStorageURL != null && zoneId != null && accountId != null && volumeId != null) {
View Full Code Here

Examples of com.cloud.storage.VMTemplateHostVO

       
        // Add the size for the templateForVmCreation if its not already present
        if ((templateForVmCreation != null) && !tmpinstalled) {
            // If the template that was passed into this allocator is not installed in the storage pool,
            // add 3 * (template size on secondary storage) to the running total
            VMTemplateHostVO templateHostVO = _storageMgr.findVmTemplateHost(templateForVmCreation.getId(), pool);

            if (templateHostVO == null) {
                VMTemplateSwiftVO templateSwiftVO = _swiftMgr.findByTmpltId(templateForVmCreation.getId());
                if (templateSwiftVO != null) {                                   
                    long templateSize = templateSwiftVO.getPhysicalSize();
                    if (templateSize == 0) {
                        templateSize = templateSwiftVO.getSize();
                    }
                    totalAllocatedSize += (templateSize + _extraBytesPerVolume);
                }
            } else {
                long templateSize = templateHostVO.getPhysicalSize();
                if ( templateSize == 0 ){
                    templateSize = templateHostVO.getSize();
                }
                totalAllocatedSize +=  (templateSize + _extraBytesPerVolume);
            }
        }
       
View Full Code Here

Examples of com.cloud.storage.VMTemplateHostVO

    }

    @Override
    public boolean templateAvailable(long templateId, long hostId) {
        VMTemplateHostVO tmpltHost = findByHostTemplate(hostId, templateId);
        if (tmpltHost == null)
            return false;

        return tmpltHost.getDownloadState() == Status.DOWNLOADED;
    }
View Full Code Here

Examples of com.cloud.storage.VMTemplateHostVO

        }
    }

    @Override
    public boolean updateState(State currentState, Event event, State nextState, DataObjectInStore vo, Object data) {
        VMTemplateHostVO templateHost = (VMTemplateHostVO) vo;
        Long oldUpdated = templateHost.getUpdatedCount();
        Date oldUpdatedTime = templateHost.getUpdated();

        SearchCriteria<VMTemplateHostVO> sc = updateStateSearch.create();
        sc.setParameters("id", templateHost.getId());
        sc.setParameters("state", currentState);
        sc.setParameters("updatedCount", templateHost.getUpdatedCount());

        templateHost.incrUpdatedCount();

        UpdateBuilder builder = getUpdateBuilder(vo);
        builder.set(vo, "state", nextState);
        builder.set(vo, "updated", new Date());

        int rows = update((VMTemplateHostVO) vo, sc);
        if (rows == 0 && s_logger.isDebugEnabled()) {
            VMTemplateHostVO dbVol = findByIdIncludingRemoved(templateHost.getId());
            if (dbVol != null) {
                StringBuilder str = new StringBuilder("Unable to update ").append(vo.toString());
                str.append(": DB Data={id=").append(dbVol.getId()).append("; state=").append(dbVol.getState())
                        .append("; updatecount=").append(dbVol.getUpdatedCount()).append(";updatedTime=")
                        .append(dbVol.getUpdated());
                str.append(": New Data={id=").append(templateHost.getId()).append("; state=").append(nextState)
                        .append("; event=").append(event).append("; updatecount=")
                        .append(templateHost.getUpdatedCount()).append("; updatedTime=")
                        .append(templateHost.getUpdated());
                str.append(": stale Data={id=").append(templateHost.getId()).append("; state=").append(currentState)
View Full Code Here

Examples of com.cloud.storage.VMTemplateHostVO

     * Tempalte is not bound to pxeserver right now, and we assume the pxeserver
     * cannot be removed once it was added. so we use host id of first found pxe
     * server as reference in template_host_ref.
     * This maybe a FIXME in future.
     */
    VMTemplateHostVO vmTemplateHost = null;
    if (zoneId == null || zoneId == -1) {
      List<DataCenterVO> dcs = _dcDao.listAllIncludingRemoved();
      for (DataCenterVO dc : dcs) {
        HostVO pxe = _resourceMgr.listAllHostsInOneZoneByType(Host.Type.BaremetalPxe, dc.getId()).get(0);

        vmTemplateHost = _tmpltHostDao.findByHostTemplate(dc.getId(), template.getId());
        if (vmTemplateHost == null) {
          vmTemplateHost = new VMTemplateHostVO(pxe.getId(), template.getId(), new Date(), 100,
              Status.DOWNLOADED, null, null, null, null, template.getUrl());
          _tmpltHostDao.persist(vmTemplateHost);
          templateCreateUsage(template, pxe);
        }
      }
    } else {
      HostVO pxe = _resourceMgr.listAllHostsInOneZoneByType(Host.Type.BaremetalPxe, zoneId).get(0);
      vmTemplateHost = new VMTemplateHostVO(pxe.getId(), template.getId(), new Date(), 100,
          Status.DOWNLOADED, null, null, null, null, template.getUrl());
      _tmpltHostDao.persist(vmTemplateHost);
      templateCreateUsage(template, pxe);
    }
   
View Full Code Here

Examples of com.cloud.storage.VMTemplateHostVO

      Account account = _accountDao.findByIdIncludingRemoved(template.getAccountId());
      String eventType = EventTypes.EVENT_TEMPLATE_DELETE;
      List<VMTemplateHostVO> templateHostVOs = _tmpltHostDao.listByTemplateId(templateId);
     
    for (VMTemplateHostVO vo : templateHostVOs) {
      VMTemplateHostVO lock = null;
      try {
        HostVO pxeServer = _hostDao.findById(vo.getHostId());
        if (!isAllZone && pxeServer.getDataCenterId() != profile.getZoneId()) {
          continue;
        }

        lock = _tmpltHostDao.acquireInLockTable(vo.getId());
        if (lock == null) {
          s_logger.debug("Failed to acquire lock when deleting templateHostVO with ID: " + vo.getId());
          success = false;
          break;
        }

        vo.setDestroyed(true);
        _tmpltHostDao.update(vo.getId(), vo);
        VMTemplateZoneVO templateZone = _tmpltZoneDao.findByZoneTemplate(pxeServer.getDataCenterId(), templateId);
        if (templateZone != null) {
          _tmpltZoneDao.remove(templateZone.getId());
        }

        UsageEventVO usageEvent = new UsageEventVO(eventType, account.getId(), pxeServer.getDataCenterId(), templateId, null);
        _usageEventDao.persist(usageEvent);
      } finally {
        if (lock != null) {
          _tmpltHostDao.releaseFromLockTable(lock.getId());
        }
      }
    }
     
      s_logger.debug("Successfully marked template host refs for template: " + template.getName() + " as destroyed in zone: " + zoneName);
 
      // If there are no more non-destroyed template host entries for this template, delete it
    if (success && (_tmpltHostDao.listByTemplateId(templateId).size() == 0)) {
      long accountId = template.getAccountId();
     
      VMTemplateVO lock = _tmpltDao.acquireInLockTable(templateId);

      try {
        if (lock == null) {
          s_logger.debug("Failed to acquire lock when deleting template with ID: " + templateId);
          success = false;
        } else if (_tmpltDao.remove(templateId)) {
          // Decrement the number of templates
            _resourceLimitMgr.decrementResourceCount(accountId, ResourceType.template);
        }

      } finally {
        if (lock != null) {
          _tmpltDao.releaseFromLockTable(lock.getId());
        }
      }
      s_logger.debug("Removed template: " + template.getName() + " because all of its template host refs were marked as destroyed.");
    }
   
View Full Code Here

Examples of com.cloud.storage.VMTemplateHostVO

                privateTemplate.setChecksum(checkSum);
                _templateDao.update(templateId, privateTemplate);

                // add template zone ref for this template
                _templateDao.addTemplateToZone(privateTemplate, zoneId);
                VMTemplateHostVO templateHostVO = new VMTemplateHostVO(
                        secondaryStorageHost.getId(), templateId);
                templateHostVO.setDownloadPercent(100);
                templateHostVO.setDownloadState(Status.DOWNLOADED);
                templateHostVO.setInstallPath(answer.getPath());
                templateHostVO.setLastUpdated(new Date());
                templateHostVO.setSize(answer.getVirtualSize());
                templateHostVO.setPhysicalSize(answer.getphysicalSize());
                _templateHostDao.persist(templateHostVO);

                UsageEventUtils.publishUsageEvent(EventTypes.EVENT_TEMPLATE_CREATE, privateTemplate.getAccountId(),
                        secondaryStorageHost.getDataCenterId(), privateTemplate.getId(),
                        privateTemplate.getName(), null, privateTemplate.getSourceTemplateId(),
                        templateHostVO.getSize(), VirtualMachineTemplate.class.getName(), privateTemplate.getUuid());
                txn.commit();
            }
        } finally {
            if (snapshot != null && snapshot.getSwiftId() != null
                    && secondaryStorageURL != null && zoneId != null
View Full Code Here

Examples of com.cloud.storage.VMTemplateHostVO

                    }

                    final String installPath = join(
                            asList("template", "tmpl", accountId,
                                    templateId), File.separator);
                    final VMTemplateHostVO tmpltHost = new VMTemplateHostVO(
                            secondaryStorageHost.getId(), templateId,
                            now(), 100, Status.DOWNLOADED, null, null,
                            null, installPath, template.getUrl());
                    tmpltHost.setSize(templateS3VO.getSize());
                    tmpltHost.setPhysicalSize(templateS3VO
                            .getPhysicalSize());
                    vmTemplateHostDao.persist(tmpltHost);

                    return null;
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.