Package com.cloud.storage

Examples of com.cloud.storage.VMTemplateVO


    }
    @Test
    public void testSelectObject() {
        cacheReplacementAlgorithm.setUnusedTimeInterval(1);
        try {
            VMTemplateVO template = new VMTemplateVO();
            template.setTemplateType(Storage.TemplateType.USER);
            template.setUrl(UUID.randomUUID().toString());
            template.setUniqueName(UUID.randomUUID().toString());
            template.setName(UUID.randomUUID().toString());
            template.setPublicTemplate(true);
            template.setFeatured(true);
            template.setRequiresHvm(true);
            template.setBits(64);
            template.setFormat(Storage.ImageFormat.VHD);
            template.setEnablePassword(true);
            template.setEnableSshKey(true);
            template.setGuestOSId(1);
            template.setBootable(true);
            template.setPrepopulate(true);
            template.setCrossZones(true);
            template.setExtractable(true);
            template = templateDao.persist(template);

            VMTemplateVO template2 = new VMTemplateVO();
            template2.setTemplateType(Storage.TemplateType.USER);
            template2.setUrl(UUID.randomUUID().toString());
            template2.setUniqueName(UUID.randomUUID().toString());
            template2.setName(UUID.randomUUID().toString());
            template2.setPublicTemplate(true);
            template2.setFeatured(true);
            template2.setRequiresHvm(true);
            template2.setBits(64);
            template2.setFormat(Storage.ImageFormat.VHD);
            template2.setEnablePassword(true);
            template2.setEnableSshKey(true);
            template2.setGuestOSId(1);
            template2.setBootable(true);
            template2.setPrepopulate(true);
            template2.setCrossZones(true);
            template2.setExtractable(true);
            template2 = templateDao.persist(template2);

            ImageStoreVO imageStoreVO = new ImageStoreVO();
            imageStoreVO.setRole(DataStoreRole.ImageCache);
            imageStoreVO.setName(UUID.randomUUID().toString());
            imageStoreVO.setProviderName(DataStoreProvider.NFS_IMAGE);
            imageStoreVO.setProtocol("nfs");
            imageStoreVO.setUrl(UUID.randomUUID().toString());
            imageStoreVO = imageStoreDao.persist(imageStoreVO);

            Calendar cal = Calendar.getInstance();
            cal.setTime(DateUtil.now());
            cal.add(Calendar.DAY_OF_MONTH, -2);
            Date date = cal.getTime();

            TemplateDataStoreVO templateStoreVO1 = new TemplateDataStoreVO();
            templateStoreVO1.setLastUpdated(date);
            templateStoreVO1.setDataStoreRole(DataStoreRole.ImageCache);
            templateStoreVO1.setDataStoreId(imageStoreVO.getId());
            templateStoreVO1.setState(ObjectInDataStoreStateMachine.State.Ready);
            templateStoreVO1.setCopy(true);
            templateStoreVO1.setTemplateId(template.getId());
            templateDataStoreDao.persist(templateStoreVO1);

            TemplateDataStoreVO templateStoreVO2 = new TemplateDataStoreVO();
            templateStoreVO2.setLastUpdated(date);
            templateStoreVO2.setDataStoreRole(DataStoreRole.ImageCache);
            templateStoreVO2.setDataStoreId(imageStoreVO.getId());
            templateStoreVO2.setState(ObjectInDataStoreStateMachine.State.Ready);
            templateStoreVO2.setCopy(true);
            templateStoreVO2.setTemplateId(template2.getId());
            templateDataStoreDao.persist(templateStoreVO2);

            DataStore store = dataStoreManager.getDataStore(imageStoreVO.getId(), DataStoreRole.ImageCache);
            Assert.assertNotNull(cacheReplacementAlgorithm.chooseOneToBeReplaced(store));
View Full Code Here


    @Test
    public void testSelectObjectFailed() {
        cacheReplacementAlgorithm.setUnusedTimeInterval(1);
        try {
            VMTemplateVO template = new VMTemplateVO();
            template.setTemplateType(Storage.TemplateType.USER);
            template.setUrl(UUID.randomUUID().toString());
            template.setUniqueName(UUID.randomUUID().toString());
            template.setName(UUID.randomUUID().toString());
            template.setPublicTemplate(true);
            template.setFeatured(true);
            template.setRequiresHvm(true);
            template.setBits(64);
            template.setFormat(Storage.ImageFormat.VHD);
            template.setEnablePassword(true);
            template.setEnableSshKey(true);
            template.setGuestOSId(1);
            template.setBootable(true);
            template.setPrepopulate(true);
            template.setCrossZones(true);
            template.setExtractable(true);
            template = templateDao.persist(template);

            VMTemplateVO template2 = new VMTemplateVO();
            template2.setTemplateType(Storage.TemplateType.USER);
            template2.setUrl(UUID.randomUUID().toString());
            template2.setUniqueName(UUID.randomUUID().toString());
            template2.setName(UUID.randomUUID().toString());
            template2.setPublicTemplate(true);
            template2.setFeatured(true);
            template2.setRequiresHvm(true);
            template2.setBits(64);
            template2.setFormat(Storage.ImageFormat.VHD);
            template2.setEnablePassword(true);
            template2.setEnableSshKey(true);
            template2.setGuestOSId(1);
            template2.setBootable(true);
            template2.setPrepopulate(true);
            template2.setCrossZones(true);
            template2.setExtractable(true);
            template2 = templateDao.persist(template2);

            ImageStoreVO imageStoreVO = new ImageStoreVO();
            imageStoreVO.setRole(DataStoreRole.ImageCache);
            imageStoreVO.setName(UUID.randomUUID().toString());
            imageStoreVO.setProviderName(DataStoreProvider.NFS_IMAGE);
            imageStoreVO.setProtocol("nfs");
            imageStoreVO.setUrl(UUID.randomUUID().toString());
            imageStoreVO = imageStoreDao.persist(imageStoreVO);


            Date date = DateUtil.now();

            TemplateDataStoreVO templateStoreVO1 = new TemplateDataStoreVO();
            templateStoreVO1.setLastUpdated(date);
            templateStoreVO1.setDataStoreRole(DataStoreRole.ImageCache);
            templateStoreVO1.setDataStoreId(imageStoreVO.getId());
            templateStoreVO1.setState(ObjectInDataStoreStateMachine.State.Ready);
            templateStoreVO1.setCopy(true);
            templateStoreVO1.setTemplateId(template.getId());
            templateDataStoreDao.persist(templateStoreVO1);

            TemplateDataStoreVO templateStoreVO2 = new TemplateDataStoreVO();
            templateStoreVO2.setLastUpdated(date);
            templateStoreVO2.setDataStoreRole(DataStoreRole.ImageCache);
            templateStoreVO2.setDataStoreId(imageStoreVO.getId());
            templateStoreVO2.setState(ObjectInDataStoreStateMachine.State.Ready);
            templateStoreVO2.setCopy(true);
            templateStoreVO2.setTemplateId(template2.getId());
            templateDataStoreDao.persist(templateStoreVO2);

            DataStore store = dataStoreManager.getDataStore(imageStoreVO.getId(), DataStoreRole.ImageCache);
            Assert.assertNull(cacheReplacementAlgorithm.chooseOneToBeReplaced(store));
View Full Code Here

    }
  }

  @Override
  public VMTemplateVO create(TemplateProfile profile) {
    VMTemplateVO template = persistTemplate(profile);
    Long zoneId = profile.getZoneId();

    // create an entry at template_store_ref with store_id = null to represent that this template is ready for use.
    TemplateDataStoreVO vmTemplateHost = new TemplateDataStoreVO(null, template.getId(), new Date(), 100,
                Status.DOWNLOADED, null, null, null, null, template.getUrl());
        this._tmpltStoreDao.persist(vmTemplateHost);

    if (zoneId == null || zoneId == -1) {
      List<DataCenterVO> dcs = _dcDao.listAllIncludingRemoved();
      if ( dcs != null && dcs.size() > 0 ){
View Full Code Here

    throw new CloudRuntimeException("Baremetal doesn't support ISO, how the delete get here???");
  }

  @Override @DB
  public boolean delete(TemplateProfile profile) {
    VMTemplateVO template = profile.getTemplate();
      Long templateId = template.getId();
      boolean success = true;
      String zoneName;

      if (!template.isCrossZones() && profile.getZoneId() != null) {
        zoneName = profile.getZoneId().toString();
      } else {
        zoneName = "all zones";
      }

      s_logger.debug("Attempting to mark template host refs for template: " + template.getName() + " as destroyed in zone: " + zoneName);
      Account account = _accountDao.findByIdIncludingRemoved(template.getAccountId());
      String eventType = EventTypes.EVENT_TEMPLATE_DELETE;
      List<TemplateDataStoreVO> templateHostVOs = this._tmpltStoreDao.listByTemplate(templateId);

    for (TemplateDataStoreVO vo : templateHostVOs) {
        TemplateDataStoreVO lock = null;
      try {
        lock = _tmpltStoreDao.acquireInLockTable(vo.getId());
        if (lock == null) {
          s_logger.debug("Failed to acquire lock when deleting templateDataStoreVO with ID: " + vo.getId());
          success = false;
          break;
        }

        vo.setDestroyed(true);
        _tmpltStoreDao.update(vo.getId(), vo);


      } finally {
        if (lock != null) {
            _tmpltStoreDao.releaseFromLockTable(lock.getId());
        }
      }
    }

    if ( profile.getZoneId() != null ){
            UsageEventVO usageEvent = new UsageEventVO(eventType, account.getId(), profile.getZoneId(), templateId, null);
            _usageEventDao.persist(usageEvent);
    }
    else{
            List<DataCenterVO> dcs = _dcDao.listAllIncludingRemoved();
            for ( DataCenterVO dc : dcs){
                UsageEventVO usageEvent = new UsageEventVO(eventType, account.getId(), dc.getId(), templateId, null);
                _usageEventDao.persist(usageEvent);
            }
    }

        VMTemplateZoneVO templateZone = _tmpltZoneDao.findByZoneTemplate(profile.getZoneId(), templateId);

        if (templateZone != null) {
            _tmpltZoneDao.remove(templateZone.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 && (_tmpltStoreDao.listByTemplate(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 and total secondary storage space used by the account.
                    _resourceLimitMgr.decrementResourceCount(accountId, ResourceType.template);
                    _resourceLimitMgr.recalculateResourceCount(accountId, template.getDomainId(),
                            ResourceType.secondary_storage.getOrdinal());
        }

      } 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

        cParams.put("role", DataStoreRole.ImageCache);
        cParams.put("url", this.getSecondaryStorage());
        cParams.put("zoneId", dcId);
        this.imageStoreHelper.createImageStore(cParams);

        VMTemplateVO image = new VMTemplateVO();
        image.setTemplateType(TemplateType.SYSTEM);
        image.setUrl(this.getTemplateUrl());
        image.setUniqueName(UUID.randomUUID().toString());
        image.setName(UUID.randomUUID().toString());
        image.setPublicTemplate(false);
        image.setFeatured(false);
        image.setRequiresHvm(false);
        image.setBits(64);
        image.setFormat(Storage.ImageFormat.VHD);
        image.setEnablePassword(false);
        image.setEnableSshKey(false);
        image.setGuestOSId(133);
        image.setBootable(true);
        image.setPrepopulate(true);
        image.setCrossZones(true);
        image.setExtractable(true);
        image.setAccountId(2);
        image = templateDao.persist(image);
        templateId = image.getId();

        // inject mockito
        LocalHostEndpoint ep = new LocalHostEndpoint();
        ep.setResource(new MockLocalNfsSecondaryStorageResource());
        Mockito.when(epSelector.select(Matchers.any(DataObject.class))).thenReturn(ep);
View Full Code Here

            @Override
            public boolean execute(Network network, VirtualRouter router) throws ResourceUnavailableException {
                // for basic zone, send vm data/password information only to the router in the same pod
                Commands cmds = new Commands(Command.OnError.Stop);
                NicVO nicVo = _nicDao.findById(nic.getId());
                VMTemplateVO template = _templateDao.findByIdIncludingRemoved(updatedProfile.getTemplateId());
                if(template != null && template.getEnablePassword()) {
      createPasswordCommand(router, updatedProfile, nicVo, cmds);
                }
                createVmDataCommand(router, vm, nicVo, SSHPublicKey, cmds);
                return sendCommandsToRouter(router, cmds);
            }
View Full Code Here

                    case LXC:
                        templateName = RouterTemplateLxc.valueIn(dest.getDataCenter().getId());
                        break;
                    default: break;
                }
                VMTemplateVO template = _templateDao.findRoutingTemplate(hType, templateName);

                if (template == null) {
                    s_logger.debug(hType + " won't support system vm, skip it");
                    continue;
                }
               
                boolean offerHA = routerOffering.getOfferHA();
                /* We don't provide HA to redundant router VMs, admin should own it all, and redundant router themselves are HA */
                if (isRedundant) {
                    offerHA = false;
                }

                router = new DomainRouterVO(id, routerOffering.getId(), vrProvider.getId(),
                VirtualMachineName.getRouterName(id, _instance), template.getId(), template.getHypervisorType(),
                template.getGuestOSId(), owner.getDomainId(), owner.getId(), isRedundant, 0, false,
                RedundantState.UNKNOWN, offerHA, false, vpcId);
                router.setDynamicallyScalable(template.isDynamicallyScalable());
                router.setRole(Role.VIRTUAL_ROUTER);
                router = _routerDao.persist(router);
                _itMgr.allocate(router.getInstanceName(), template, routerOffering, networks, plan, null);
                router = _routerDao.findById(router.getId());
            } catch (InsufficientCapacityException ex) {
View Full Code Here

        if (!allowToLaunchNew(dataCenterId)) {
            s_logger.warn("The number of launched console proxy on zone " + dataCenterId + " has reached to limit");
            return null;
        }

        VMTemplateVO template = null;
        HypervisorType availableHypervisor = _resourceMgr.getAvailableHypervisor(dataCenterId);
        template = _templateDao.findSystemVMReadyTemplate(dataCenterId, availableHypervisor);
        if (template == null) {
            throw new CloudRuntimeException("Not able to find the System templates or not downloaded in zone " + dataCenterId);
        }
View Full Code Here

    }

    public boolean isZoneReady(Map<Long, ZoneHostInfo> zoneHostInfoMap, long dataCenterId) {
        ZoneHostInfo zoneHostInfo = zoneHostInfoMap.get(dataCenterId);
        if (zoneHostInfo != null && isZoneHostReady(zoneHostInfo)) {
            VMTemplateVO template = _templateDao.findSystemVMReadyTemplate(dataCenterId, HypervisorType.Any);
            if (template == null) {
                if (s_logger.isDebugEnabled()) {
                    s_logger.debug("System vm template is not ready at data center " + dataCenterId + ", wait until it is ready to launch console proxy vm");
                }
                return false;
            }
            TemplateDataStoreVO templateHostRef = _vmTemplateStoreDao.findByTemplateZoneDownloadStatus(template.getId(), dataCenterId,
                    Status.DOWNLOADED);

            if (templateHostRef != null) {
                List<Pair<Long, Integer>> l = _consoleProxyDao.getDatacenterStoragePoolHostInfo(dataCenterId, _use_lvm);
                if (l != null && l.size() > 0 && l.get(0).second().intValue() > 0) {
                    return true;
                } else {
                    if (s_logger.isDebugEnabled()) {
                        s_logger.debug("Primary storage is not ready, wait until it is ready to launch console proxy");
                    }
                }
            } else {
                if (s_logger.isDebugEnabled()) {
                    if (template == null) {
                        s_logger.debug("Zone host is ready, but console proxy template is null");
                    } else {
                        s_logger.debug("Zone host is ready, but console proxy template: " + template.getId() + " is not ready on secondary storage.");
                    }
                }
            }
        }
        return false;
View Full Code Here

        if (userVm == null) {
            throw new InvalidParameterValueException(
                    "unable to find a virtual machine with id " + cmd.getId());
        }

        VMTemplateVO template = _templateDao.findByIdIncludingRemoved(userVm
                .getTemplateId());
        if (template == null || !template.getEnablePassword()) {
            throw new InvalidParameterValueException(
                    "Fail to reset password for the virtual machine, the template is not password enabled");
        }

        if (userVm.getState() == State.Error
View Full Code Here

TOP

Related Classes of com.cloud.storage.VMTemplateVO

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.