Package com.cloud.storage.template

Examples of com.cloud.storage.template.TemplateInfo


            List<MockVolumeVO> templates = _mockVolumeDao.findByStorageIdAndType(storage.getId(),
                    MockVolumeType.TEMPLATE);

            Map<String, TemplateInfo> templateInfos = new HashMap<String, TemplateInfo>();
            for (MockVolumeVO template : templates) {
                templateInfos.put(template.getName(), new TemplateInfo(template.getName(), template.getPath()
                        .replaceAll(storage.getMountPoint(), ""), template.getSize(), template.getSize(), true, false));
            }
            txn.commit();
            return new ListTemplateAnswer(cmd.getSecUrl(), templateInfos);
        } catch (Exception ex) {
View Full Code Here


          return;
      }
      Long hostId = host.getId();
      List<VMTemplateVO> rtngTmplts = _templateDao.listAllSystemVMTemplates();
      for ( VMTemplateVO tmplt : rtngTmplts ) {
          TemplateInfo tmpltInfo = templateInfos.get(tmplt.getUniqueName());
          if ( tmpltInfo == null ) {
              continue;
          }
          VMTemplateHostVO tmpltHost = _vmTemplateHostDao.findByHostTemplate(hostId, tmplt.getId());
          if ( tmpltHost == null ) {
                tmpltHost = new VMTemplateHostVO(hostId, tmplt.getId(), new Date(), 100, Status.DOWNLOADED, null, null, null, tmpltInfo.getInstallPath(), tmplt.getUrl());
              tmpltHost.setSize(tmpltInfo.getSize());
              tmpltHost.setPhysicalSize(tmpltInfo.getPhysicalSize());
              _vmTemplateHostDao.persist(tmpltHost);
          }
      }
  }
View Full Code Here

        List<VolumeHostVO> toBeDownloaded = new ArrayList<VolumeHostVO>(dbVolumes);
        for (VolumeHostVO volumeHost : dbVolumes){
          VolumeVO volume = _volumeDao.findById(volumeHost.getVolumeId());
          //Exists then don't download
          if (volumeInfos.containsKey(volume.getId())){
                TemplateInfo volInfo = volumeInfos.remove(volume.getId());
                toBeDownloaded.remove(volumeHost);               
                s_logger.info("Volume Sync found " + volume.getUuid() + " already in the volume host table");
                if (volumeHost.getDownloadState() != Status.DOWNLOADED) {
                  volumeHost.setErrorString("");
                }
                if (volInfo.isCorrupted()) {
                  volumeHost.setDownloadState(Status.DOWNLOAD_ERROR);
                    String msg = "Volume " + volume.getUuid() + " is corrupted on secondary storage ";
                    volumeHost.setErrorString(msg);
                    s_logger.info("msg");
                    if (volumeHost.getDownloadUrl() == null) {
                        msg = "Volume (" + volume.getUuid() + ") with install path " + volInfo.getInstallPath() + "is corrupted, please check in secondary storage: " + volumeHost.getHostId();
                        s_logger.warn(msg);
                    } else {
                        toBeDownloaded.add(volumeHost);
                    }

                } else { // Put them in right status
                  volumeHost.setDownloadPercent(100);
                  volumeHost.setDownloadState(Status.DOWNLOADED);
                  volumeHost.setInstallPath(volInfo.getInstallPath());
                  volumeHost.setSize(volInfo.getSize());
                  volumeHost.setPhysicalSize(volInfo.getPhysicalSize());
                  volumeHost.setLastUpdated(new Date());              
                  _volumeHostDao.update(volumeHost.getId(), volumeHost);
                }
                continue;
          }
          // Volume is not on secondary but we should download.
          if (volumeHost.getDownloadState() != Status.DOWNLOADED) {
                s_logger.info("Volume Sync did not find " + volume.getName() + " ready on server " + sserverId + ", will request download to start/resume shortly");
                toBeDownloaded.add(volumeHost);
            }
        }
       
        //Download volumes which haven't been downloaded yet.
        if (toBeDownloaded.size() > 0) {
            for (VolumeHostVO volumeHost : toBeDownloaded) {
                if (volumeHost.getDownloadUrl() == null) { // If url is null we can't initiate the download
                    continue;
                }                                 
                s_logger.debug("Volume " + volumeHost.getVolumeId() + " needs to be downloaded to " + ssHost.getName());
                downloadVolumeToStorage(_volumeDao.findById(volumeHost.getVolumeId()), ssHost,  volumeHost.getDownloadUrl(), volumeHost.getChecksum(), volumeHost.getFormat());               
            }
        }

        //Delete volumes which are not present on DB.
        for (Long uniqueName : volumeInfos.keySet()) {
            TemplateInfo vInfo = volumeInfos.get(uniqueName);
            DeleteVolumeCommand dtCommand = new DeleteVolumeCommand(ssHost.getStorageUrl(), vInfo.getInstallPath());
            try {
              _agentMgr.sendToSecStorage(ssHost, dtCommand, null);
            } catch (AgentUnavailableException e) {
                String err = "Failed to delete " + vInfo.getTemplateName() + " on secondary storage " + sserverId + " which isn't in the database";
                s_logger.error(err);
                return;
            }
           
            String description = "Deleted volume " + vInfo.getTemplateName() + " on secondary storage " + sserverId + " since it isn't in the database";
            s_logger.info(description);
        }
    }
View Full Code Here

        for (VMTemplateVO tmplt : allTemplates) {
            String uniqueName = tmplt.getUniqueName();
            VMTemplateHostVO tmpltHost = _vmTemplateHostDao.findByHostTemplate(sserverId, tmplt.getId());
            if (templateInfos.containsKey(uniqueName)) {
                TemplateInfo tmpltInfo = templateInfos.remove(uniqueName);
                toBeDownloaded.remove(tmplt);
                if (tmpltHost != null) {
                    s_logger.info("Template Sync found " + uniqueName + " already in the template host table");
                    if (tmpltHost.getDownloadState() != Status.DOWNLOADED) {
                        tmpltHost.setErrorString("");
                    }
                    if (tmpltInfo.isCorrupted()) {
                        tmpltHost.setDownloadState(Status.DOWNLOAD_ERROR);
                        String msg = "Template " + tmplt.getName() + ":" + tmplt.getId() + " is corrupted on secondary storage " + tmpltHost.getId();
                        tmpltHost.setErrorString(msg);
                        s_logger.info("msg");
                        if (tmplt.getUrl() == null) {
                            msg = "Private Template (" + tmplt + ") with install path " + tmpltInfo.getInstallPath() + "is corrupted, please check in secondary storage: " + tmpltHost.getHostId();
                            s_logger.warn(msg);
                        } else {
                            toBeDownloaded.add(tmplt);
                        }

                    } else {
                        tmpltHost.setDownloadPercent(100);
                        tmpltHost.setDownloadState(Status.DOWNLOADED);
                        tmpltHost.setInstallPath(tmpltInfo.getInstallPath());
                        tmpltHost.setSize(tmpltInfo.getSize());
                        tmpltHost.setPhysicalSize(tmpltInfo.getPhysicalSize());
                        tmpltHost.setLastUpdated(new Date());
                    }
                    _vmTemplateHostDao.update(tmpltHost.getId(), tmpltHost);
                } else {
                    tmpltHost = new VMTemplateHostVO(sserverId, tmplt.getId(), new Date(), 100, Status.DOWNLOADED, null, null, null, tmpltInfo.getInstallPath(), tmplt.getUrl());
                    tmpltHost.setSize(tmpltInfo.getSize());
                    tmpltHost.setPhysicalSize(tmpltInfo.getPhysicalSize());
                    _vmTemplateHostDao.persist(tmpltHost);
                    VMTemplateZoneVO tmpltZoneVO = _vmTemplateZoneDao.findByZoneTemplate(zoneId, tmplt.getId());
                    if (tmpltZoneVO == null) {
                        tmpltZoneVO = new VMTemplateZoneVO(zoneId, tmplt.getId(), new Date());
                        _vmTemplateZoneDao.persist(tmpltZoneVO);
                    } else {
                        tmpltZoneVO.setLastUpdated(new Date());
                        _vmTemplateZoneDao.update(tmpltZoneVO.getId(), tmpltZoneVO);
                    }

                }

                continue;
            }
            if (tmpltHost != null && tmpltHost.getDownloadState() != Status.DOWNLOADED) {
                s_logger.info("Template Sync did not find " + uniqueName + " ready on server " + sserverId + ", will request download to start/resume shortly");

            } else if (tmpltHost == null) {
                s_logger.info("Template Sync did not find " + uniqueName + " on the server " + sserverId + ", will request download shortly");
                VMTemplateHostVO templtHost = new VMTemplateHostVO(sserverId, tmplt.getId(), new Date(), 0, Status.NOT_DOWNLOADED, null, null, null, null, tmplt.getUrl());
                _vmTemplateHostDao.persist(templtHost);
                VMTemplateZoneVO tmpltZoneVO = _vmTemplateZoneDao.findByZoneTemplate(zoneId, tmplt.getId());
                if (tmpltZoneVO == null) {
                    tmpltZoneVO = new VMTemplateZoneVO(zoneId, tmplt.getId(), new Date());
                    _vmTemplateZoneDao.persist(tmpltZoneVO);
                } else {
                    tmpltZoneVO.setLastUpdated(new Date());
                    _vmTemplateZoneDao.update(tmpltZoneVO.getId(), tmpltZoneVO);
                }
            }

        }

        if (toBeDownloaded.size() > 0) {
            /* Only download templates whose hypervirsor type is in the zone */
            List<HypervisorType> availHypers = _clusterDao.getAvailableHypervisorInZone(zoneId);
            if (availHypers.isEmpty()) {
                /*
                 * This is for cloudzone, local secondary storage resource
                 * started before cluster created
                 */
                availHypers.add(HypervisorType.KVM);
            }
            /* Baremetal need not to download any template */
            availHypers.remove(HypervisorType.BareMetal);
            availHypers.add(HypervisorType.None); // bug 9809: resume ISO
                                                  // download.
            for (VMTemplateVO tmplt : toBeDownloaded) {
                if (tmplt.getUrl() == null) { // If url is null we can't
                                              // initiate the download
                    continue;
                }
                // if this is private template, and there is no record for this
                // template in this sHost, skip
                if (!tmplt.isPublicTemplate() && !tmplt.isFeatured()) {
                    VMTemplateHostVO tmpltHost = _vmTemplateHostDao.findByHostTemplate(sserverId, tmplt.getId());
                    if (tmpltHost == null) {
                        continue;
                    }
                }
                if (availHypers.contains(tmplt.getHypervisorType())) {
                    if (_swiftMgr.isSwiftEnabled()) {
                        if (_swiftMgr.isTemplateInstalled(tmplt.getId())) {
                            continue;
                        }
                    }
                    s_logger.debug("Template " + tmplt.getName() + " needs to be downloaded to " + ssHost.getName());
                    downloadTemplateToStorage(tmplt, ssHost);
                }
            }
        }

        for (String uniqueName : templateInfos.keySet()) {
            TemplateInfo tInfo = templateInfos.get(uniqueName);
            DeleteTemplateCommand dtCommand = new DeleteTemplateCommand(ssHost.getStorageUrl(), tInfo.getInstallPath());
            try {
              _agentMgr.sendToSecStorage(ssHost, dtCommand, null);
            } catch (AgentUnavailableException e) {
                String err = "Failed to delete " + tInfo.getTemplateName() + " on secondary storage " + sserverId + " which isn't in the database";
                s_logger.error(err);
                return;
            }

            String description = "Deleted template " + tInfo.getTemplateName() + " on secondary storage " + sserverId + " since it isn't in the database";
            s_logger.info(description);
        }
    }
View Full Code Here

          return;
      }
      Long hostId = host.getId();
      List<VMTemplateVO> rtngTmplts = _templateDao.listAllSystemVMTemplates();
      for ( VMTemplateVO tmplt : rtngTmplts ) {
          TemplateInfo tmpltInfo = templateInfos.get(tmplt.getUniqueName());
          if ( tmpltInfo == null ) {
              continue;
          }
          VMTemplateHostVO tmpltHost = _vmTemplateHostDao.findByHostTemplate(hostId, tmplt.getId());
          if ( tmpltHost == null ) {
                tmpltHost = new VMTemplateHostVO(hostId, tmplt.getId(), new Date(), 100, Status.DOWNLOADED, null, null, null, tmpltInfo.getInstallPath(), tmplt.getUrl());
              tmpltHost.setSize(tmpltInfo.getSize());
              tmpltHost.setPhysicalSize(tmpltInfo.getPhysicalSize());
              _vmTemplateHostDao.persist(tmpltHost);
          }
      }
  }
View Full Code Here

        List<VolumeHostVO> toBeDownloaded = new ArrayList<VolumeHostVO>(dbVolumes);
        for (VolumeHostVO volumeHost : dbVolumes){
          VolumeVO volume = _volumeDao.findById(volumeHost.getVolumeId());
          //Exists then don't download
          if (volumeInfos.containsKey(volume.getId())){
                TemplateInfo volInfo = volumeInfos.remove(volume.getId());
                toBeDownloaded.remove(volumeHost);               
                s_logger.info("Volume Sync found " + volume.getUuid() + " already in the volume host table");
                if (volumeHost.getDownloadState() != Status.DOWNLOADED) {
                  volumeHost.setErrorString("");
                }
                if (volInfo.isCorrupted()) {
                  volumeHost.setDownloadState(Status.DOWNLOAD_ERROR);
                    String msg = "Volume " + volume.getUuid() + " is corrupted on secondary storage ";
                    volumeHost.setErrorString(msg);
                    s_logger.info("msg");
                    if (volumeHost.getDownloadUrl() == null) {
                        msg = "Volume (" + volume.getUuid() + ") with install path " + volInfo.getInstallPath() + "is corrupted, please check in secondary storage: " + volumeHost.getHostId();
                        s_logger.warn(msg);
                    } else {
                        toBeDownloaded.add(volumeHost);
                    }

                } else { // Put them in right status
                  volumeHost.setDownloadPercent(100);
                  volumeHost.setDownloadState(Status.DOWNLOADED);
                  volumeHost.setInstallPath(volInfo.getInstallPath());
                  volumeHost.setSize(volInfo.getSize());
                  volumeHost.setPhysicalSize(volInfo.getPhysicalSize());
                  volumeHost.setLastUpdated(new Date());              
                  _volumeHostDao.update(volumeHost.getId(), volumeHost);
                }
                continue;
          }
          // Volume is not on secondary but we should download.
          if (volumeHost.getDownloadState() != Status.DOWNLOADED) {
                s_logger.info("Volume Sync did not find " + volume.getName() + " ready on server " + sserverId + ", will request download to start/resume shortly");
                toBeDownloaded.add(volumeHost);
            }
        }
       
        //Download volumes which haven't been downloaded yet.
        if (toBeDownloaded.size() > 0) {
            for (VolumeHostVO volumeHost : toBeDownloaded) {
                if (volumeHost.getDownloadUrl() == null) { // If url is null we can't initiate the download
                    continue;
                }                                 
                s_logger.debug("Volume " + volumeHost.getVolumeId() + " needs to be downloaded to " + ssHost.getName());
                downloadVolumeToStorage(_volumeDao.findById(volumeHost.getVolumeId()), ssHost,  volumeHost.getDownloadUrl(), volumeHost.getChecksum(), volumeHost.getFormat());               
            }
        }

        //Delete volumes which are not present on DB.
        for (Long uniqueName : volumeInfos.keySet()) {
            TemplateInfo vInfo = volumeInfos.get(uniqueName);
            DeleteVolumeCommand dtCommand = new DeleteVolumeCommand(ssHost.getStorageUrl(), vInfo.getInstallPath());
            try {
              _agentMgr.sendToSecStorage(ssHost, dtCommand, null);
            } catch (AgentUnavailableException e) {
                String err = "Failed to delete " + vInfo.getTemplateName() + " on secondary storage " + sserverId + " which isn't in the database";
                s_logger.error(err);
                return;
            }
           
            String description = "Deleted volume " + vInfo.getTemplateName() + " on secondary storage " + sserverId + " since it isn't in the database";
            s_logger.info(description);
        }
    }
View Full Code Here

        for (VMTemplateVO tmplt : allTemplates) {
            String uniqueName = tmplt.getUniqueName();
            VMTemplateHostVO tmpltHost = _vmTemplateHostDao.findByHostTemplate(sserverId, tmplt.getId());
            if (templateInfos.containsKey(uniqueName)) {
                TemplateInfo tmpltInfo = templateInfos.remove(uniqueName);
                toBeDownloaded.remove(tmplt);
                if (tmpltHost != null) {
                    s_logger.info("Template Sync found " + uniqueName + " already in the template host table");
                    if (tmpltHost.getDownloadState() != Status.DOWNLOADED) {
                        tmpltHost.setErrorString("");
                    }
                    if (tmpltInfo.isCorrupted()) {
                        tmpltHost.setDownloadState(Status.DOWNLOAD_ERROR);
                        String msg = "Template " + tmplt.getName() + ":" + tmplt.getId() + " is corrupted on secondary storage " + tmpltHost.getId();
                        tmpltHost.setErrorString(msg);
                        s_logger.info("msg");
                        if (tmplt.getUrl() == null) {
                            msg = "Private Template (" + tmplt + ") with install path " + tmpltInfo.getInstallPath() + "is corrupted, please check in secondary storage: " + tmpltHost.getHostId();
                            s_logger.warn(msg);
                        } else {
                            toBeDownloaded.add(tmplt);
                        }

                    } else {
                        tmpltHost.setDownloadPercent(100);
                        tmpltHost.setDownloadState(Status.DOWNLOADED);
                        tmpltHost.setInstallPath(tmpltInfo.getInstallPath());
                        tmpltHost.setSize(tmpltInfo.getSize());
                        tmpltHost.setPhysicalSize(tmpltInfo.getPhysicalSize());
                        tmpltHost.setLastUpdated(new Date());
                    }
                    _vmTemplateHostDao.update(tmpltHost.getId(), tmpltHost);
                } else {
                    tmpltHost = new VMTemplateHostVO(sserverId, tmplt.getId(), new Date(), 100, Status.DOWNLOADED, null, null, null, tmpltInfo.getInstallPath(), tmplt.getUrl());
                    tmpltHost.setSize(tmpltInfo.getSize());
                    tmpltHost.setPhysicalSize(tmpltInfo.getPhysicalSize());
                    _vmTemplateHostDao.persist(tmpltHost);
                    VMTemplateZoneVO tmpltZoneVO = _vmTemplateZoneDao.findByZoneTemplate(zoneId, tmplt.getId());
                    if (tmpltZoneVO == null) {
                        tmpltZoneVO = new VMTemplateZoneVO(zoneId, tmplt.getId(), new Date());
                        _vmTemplateZoneDao.persist(tmpltZoneVO);
                    } else {
                        tmpltZoneVO.setLastUpdated(new Date());
                        _vmTemplateZoneDao.update(tmpltZoneVO.getId(), tmpltZoneVO);
                    }

                }

                continue;
            }
            if (tmpltHost != null && tmpltHost.getDownloadState() != Status.DOWNLOADED) {
                s_logger.info("Template Sync did not find " + uniqueName + " ready on server " + sserverId + ", will request download to start/resume shortly");

            } else if (tmpltHost == null) {
                s_logger.info("Template Sync did not find " + uniqueName + " on the server " + sserverId + ", will request download shortly");
                VMTemplateHostVO templtHost = new VMTemplateHostVO(sserverId, tmplt.getId(), new Date(), 0, Status.NOT_DOWNLOADED, null, null, null, null, tmplt.getUrl());
                _vmTemplateHostDao.persist(templtHost);
                VMTemplateZoneVO tmpltZoneVO = _vmTemplateZoneDao.findByZoneTemplate(zoneId, tmplt.getId());
                if (tmpltZoneVO == null) {
                    tmpltZoneVO = new VMTemplateZoneVO(zoneId, tmplt.getId(), new Date());
                    _vmTemplateZoneDao.persist(tmpltZoneVO);
                } else {
                    tmpltZoneVO.setLastUpdated(new Date());
                    _vmTemplateZoneDao.update(tmpltZoneVO.getId(), tmpltZoneVO);
                }
            }

        }

        if (toBeDownloaded.size() > 0) {
            /* Only download templates whose hypervirsor type is in the zone */
            List<HypervisorType> availHypers = _clusterDao.getAvailableHypervisorInZone(zoneId);
            if (availHypers.isEmpty()) {
                /*
                 * This is for cloudzone, local secondary storage resource
                 * started before cluster created
                 */
                availHypers.add(HypervisorType.KVM);
            }
            /* Baremetal need not to download any template */
            availHypers.remove(HypervisorType.BareMetal);
            availHypers.add(HypervisorType.None); // bug 9809: resume ISO
                                                  // download.
            for (VMTemplateVO tmplt : toBeDownloaded) {
                if (tmplt.getUrl() == null) { // If url is null we can't
                                              // initiate the download
                    continue;
                }
                // if this is private template, and there is no record for this
                // template in this sHost, skip
                if (!tmplt.isPublicTemplate() && !tmplt.isFeatured()) {
                    VMTemplateHostVO tmpltHost = _vmTemplateHostDao.findByHostTemplate(sserverId, tmplt.getId());
                    if (tmpltHost == null) {
                        continue;
                    }
                }
                if (availHypers.contains(tmplt.getHypervisorType())) {
                    if (_swiftMgr.isSwiftEnabled()) {
                        if (_swiftMgr.isTemplateInstalled(tmplt.getId())) {
                            continue;
                        }
                    }
                    s_logger.debug("Template " + tmplt.getName() + " needs to be downloaded to " + ssHost.getName());
                    downloadTemplateToStorage(tmplt, ssHost);
                }
            }
        }

        for (String uniqueName : templateInfos.keySet()) {
            TemplateInfo tInfo = templateInfos.get(uniqueName);
            DeleteTemplateCommand dtCommand = new DeleteTemplateCommand(ssHost.getStorageUrl(), tInfo.getInstallPath());
            try {
              _agentMgr.sendToSecStorage(ssHost, dtCommand, null);
            } catch (AgentUnavailableException e) {
                String err = "Failed to delete " + tInfo.getTemplateName() + " on secondary storage " + sserverId + " which isn't in the database";
                s_logger.error(err);
                return;
            }

            String description = "Deleted template " + tInfo.getTemplateName() + " on secondary storage " + sserverId + " since it isn't in the database";
            s_logger.info(description);
        }
    }
View Full Code Here

    public Map<String, TemplateInfo> getDefaultSystemVmTemplateInfo() {         
        List<VMTemplateVO> tmplts = _tmpltDao.listAllSystemVMTemplates();
        Map<String, TemplateInfo> tmpltInfo = new HashMap<String, TemplateInfo>();
        if (tmplts != null) {
            for (VMTemplateVO tmplt : tmplts) {
                TemplateInfo routingInfo = new TemplateInfo(tmplt.getUniqueName(), TemplateConstants.DEFAULT_SYSTEM_VM_TEMPLATE_PATH + tmplt.getId() + File.separator, false, false);
                tmpltInfo.put(tmplt.getUniqueName(), routingInfo);
            }
        }
        return tmpltInfo;
    }
View Full Code Here

                    }
                } catch (IOException e) {
                    s_logger.warn("Unable to load template location " + ldir + " due to " + e.toString(), e);
                    continue;
                }
                TemplateInfo tInfo = loc.getTemplateInfo();
                tInfo.setInstallPath(container);
                tmpltInfos.put(tInfo.getTemplateName(), tInfo);
                loc.purge();
                deleteLocalDir(ldir);
            }
        }
        return tmpltInfos;
View Full Code Here

TOP

Related Classes of com.cloud.storage.template.TemplateInfo

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.