gpt4 book ai didi

org.apache.cloudstack.engine.subsystem.api.storage.ZoneScope类的使用及代码示例

转载 作者:知者 更新时间:2024-03-15 00:24:49 26 4
gpt4 key购买 nike

本文整理了Java中org.apache.cloudstack.engine.subsystem.api.storage.ZoneScope类的一些代码示例,展示了ZoneScope类的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。ZoneScope类的具体详情如下:
包路径:org.apache.cloudstack.engine.subsystem.api.storage.ZoneScope
类名称:ZoneScope

ZoneScope介绍

暂无

代码示例

代码示例来源:origin: apache/cloudstack

private Scope getZoneScope(Scope scope) {
  ZoneScope zoneScope;
  if (scope instanceof ClusterScope) {
    ClusterScope clusterScope = (ClusterScope)scope;
    zoneScope = new ZoneScope(clusterScope.getZoneId());
  } else if (scope instanceof HostScope) {
    HostScope hostScope = (HostScope)scope;
    zoneScope = new ZoneScope(hostScope.getZoneId());
  } else {
    zoneScope = (ZoneScope)scope;
  }
  return zoneScope;
}

代码示例来源:origin: apache/cloudstack

@Override
public boolean attachZone(DataStore dataStore, ZoneScope scope, Hypervisor.HypervisorType hypervisorType) {
  dataStoreHelper.attachZone(dataStore);
  List<HostVO> xenServerHosts = _resourceMgr.listAllUpAndEnabledHostsInOneZoneByHypervisor(Hypervisor.HypervisorType.XenServer, scope.getScopeId());
  List<HostVO> vmWareServerHosts = _resourceMgr.listAllUpAndEnabledHostsInOneZoneByHypervisor(Hypervisor.HypervisorType.VMware, scope.getScopeId());
  List<HostVO> kvmHosts = _resourceMgr.listAllUpAndEnabledHostsInOneZoneByHypervisor(Hypervisor.HypervisorType.KVM, scope.getScopeId());
  List<HostVO> hosts = new ArrayList<HostVO>();
  hosts.addAll(xenServerHosts);
  hosts.addAll(vmWareServerHosts);
  hosts.addAll(kvmHosts);
  for (HostVO host : hosts) {
    try {
      _storageMgr.connectHostToSharedPool(host.getId(), dataStore.getId());
    } catch (Exception e) {
      logger.warn("Unable to establish a connection between " + host + " and " + dataStore, e);
    }
  }
  return true;
}

代码示例来源:origin: apache/cloudstack

@Override
public Scope getScope() {
  return new ZoneScope(imageDataStoreVO.getDataCenterId());
}

代码示例来源:origin: apache/cloudstack

@Override
public boolean attachZone(DataStore dataStore, ZoneScope scope, HypervisorType hypervisorType) {
  List<HostVO> xenServerHosts = _resourceMgr.listAllUpAndEnabledHostsInOneZoneByHypervisor(HypervisorType.XenServer, scope.getScopeId());
  List<HostVO> vmWareServerHosts = _resourceMgr.listAllUpAndEnabledHostsInOneZoneByHypervisor(HypervisorType.VMware, scope.getScopeId());
  List<HostVO> kvmHosts = _resourceMgr.listAllUpAndEnabledHostsInOneZoneByHypervisor(HypervisorType.KVM, scope.getScopeId());
  List<HostVO> hosts = new ArrayList<>();
  hosts.addAll(xenServerHosts);
  hosts.addAll(vmWareServerHosts);
  hosts.addAll(kvmHosts);
  for (HostVO host : hosts) {
    try {
      _storageMgr.connectHostToSharedPool(host.getId(), dataStore.getId());
    } catch (Exception e) {
      s_logger.warn("Unable to establish a connection between " + host + " and " + dataStore, e);
    }
  }
  _dataStoreHelper.attachZone(dataStore);
  return true;
}

代码示例来源:origin: apache/cloudstack

private Scope getZoneScope(Scope destScope) {
  ZoneScope zoneScope = null;
  if (destScope instanceof ClusterScope) {
    ClusterScope clusterScope = (ClusterScope)destScope;
    zoneScope = new ZoneScope(clusterScope.getZoneId());
  } else if (destScope instanceof HostScope) {
    HostScope hostScope = (HostScope)destScope;
    zoneScope = new ZoneScope(hostScope.getZoneId());
  } else {
    zoneScope = (ZoneScope)destScope;
  }
  return zoneScope;
}

代码示例来源:origin: apache/cloudstack

@Override
public List<ImageStoreVO> findImageCacheByScope(ZoneScope scope) {
  SearchCriteria<ImageStoreVO> sc = createSearchCriteria();
  sc.addAnd("role", SearchCriteria.Op.EQ, DataStoreRole.ImageCache);
  if (scope.getScopeId() != null) {
    sc.addAnd("scope", SearchCriteria.Op.EQ, ScopeType.ZONE);
    sc.addAnd("dcId", SearchCriteria.Op.EQ, scope.getScopeId());
  }
  return listBy(sc);
}

代码示例来源:origin: apache/cloudstack

@Override
public DataStore getImageStore(long zoneId) {
  List<DataStore> stores = getImageStoresByScope(new ZoneScope(zoneId));
  if (stores == null || stores.size() == 0) {
    return null;
  }
  return imageDataStoreMgr.getImageStore(stores);
}

代码示例来源:origin: apache/cloudstack

@Override
public boolean attachZone(DataStore dataStore, ZoneScope scope, HypervisorType hypervisorType) {
  List<HostVO> hosts = _resourceMgr.listAllUpAndEnabledHostsInOneZoneByHypervisor(hypervisorType, scope.getScopeId());
  s_logger.debug("In createPool. Attaching the pool to each of the hosts.");
  List<HostVO> poolHosts = new ArrayList<HostVO>();
  for (HostVO host : hosts) {
    try {
      storageMgr.connectHostToSharedPool(host.getId(), dataStore.getId());
      poolHosts.add(host);
    } catch (Exception e) {
      s_logger.warn("Unable to establish a connection between " + host + " and " + dataStore, e);
    }
  }
  if (poolHosts.isEmpty()) {
    s_logger.warn("No host can access storage pool " + dataStore + " in this zone.");
    primaryDataStoreDao.expunge(dataStore.getId());
    throw new CloudRuntimeException("Failed to create storage pool as it is not accessible to hosts.");
  }
  dataStoreHelper.attachZone(dataStore, hypervisorType);
  return true;
}

代码示例来源:origin: apache/cloudstack

@Override
public DataStore getImageCacheStore(long zoneId) {
  List<DataStore> stores = getImageCacheStores(new ZoneScope(zoneId));
  if (stores == null || stores.size() == 0) {
    return null;
  }
  return imageDataStoreMgr.getImageStore(stores);
}

代码示例来源:origin: apache/cloudstack

@Override
public List<ImageStoreVO> findByScope(ZoneScope scope) {
  SearchCriteria<ImageStoreVO> sc = createSearchCriteria();
  sc.addAnd("role", SearchCriteria.Op.EQ, DataStoreRole.Image);
  if (scope.getScopeId() != null) {
    SearchCriteria<ImageStoreVO> scc = createSearchCriteria();
    scc.addOr("scope", SearchCriteria.Op.EQ, ScopeType.REGION);
    scc.addOr("dcId", SearchCriteria.Op.EQ, scope.getScopeId());
    sc.addAnd("scope", SearchCriteria.Op.SC, scc);
  }
  // we should return all image stores if cross-zone scope is passed
  // (scopeId = null)
  return listBy(sc);
}

代码示例来源:origin: apache/cloudstack

@Override
public TemplateDataStoreVO findByTemplateZoneDownloadStatus(long templateId, Long zoneId, Status... status) {
  // get all elgible image stores
  List<DataStore> imgStores = _storeMgr.getImageStoresByScope(new ZoneScope(zoneId));
  if (imgStores != null) {
    for (DataStore store : imgStores) {
      List<TemplateDataStoreVO> sRes = listByTemplateStoreDownloadStatus(templateId, store.getId(), status);
      if (sRes != null && sRes.size() > 0) {
        Collections.shuffle(sRes);
        return sRes.get(0);
      }
    }
  }
  return null;
}

代码示例来源:origin: apache/cloudstack

@Override
public boolean attachZone(DataStore dataStore, ZoneScope scope, HypervisorType hypervisorType) {
  List<HostVO> hosts = _resourceMgr.listAllUpAndEnabledHostsInOneZoneByHypervisor(hypervisorType, scope.getScopeId());
  s_logger.debug("In createPool. Attaching the pool to each of the hosts.");
  List<HostVO> poolHosts = new ArrayList<HostVO>();
  for (HostVO host : hosts) {
    try {
      storageMgr.connectHostToSharedPool(host.getId(), dataStore.getId());
      poolHosts.add(host);
    } catch (StorageConflictException se) {
        primaryDataStoreDao.expunge(dataStore.getId());
        throw new CloudRuntimeException("Storage has already been added as local storage to host: " + host.getName());
    } catch (Exception e) {
      s_logger.warn("Unable to establish a connection between " + host + " and " + dataStore, e);
    }
  }
  if (poolHosts.isEmpty()) {
    s_logger.warn("No host can access storage pool " + dataStore + " in this zone.");
    primaryDataStoreDao.expunge(dataStore.getId());
    throw new CloudRuntimeException("Failed to create storage pool as it is not accessible to hosts.");
  }
  dataStoreHelper.attachZone(dataStore, hypervisorType);
  return true;
}

代码示例来源:origin: apache/cloudstack

@Override
public List<DataStore> getImageStoreByTemplate(long templateId, Long zoneId) {
  // find all eligible image stores for this zone scope
  List<DataStore> imageStores = _dataStoreMgr.getImageStoresByScope(new ZoneScope(zoneId));
  if (imageStores == null || imageStores.size() == 0) {
    return null;
  }
  List<DataStore> stores = new ArrayList<DataStore>();
  for (DataStore store : imageStores) {
    // check if the template is stored there
    List<TemplateDataStoreVO> storeTmpl = _tmplStoreDao.listByTemplateStore(templateId, store.getId());
    if (storeTmpl != null && storeTmpl.size() > 0) {
      stores.add(store);
    }
  }
  return stores;
}

代码示例来源:origin: apache/cloudstack

@Override
public TemplateDataStoreVO findByTemplateZoneReady(long templateId, Long zoneId) {
  List<DataStore> imgStores = null;
  imgStores = _storeMgr.getImageStoresByScope(new ZoneScope(zoneId));
  if (imgStores != null) {
    Collections.shuffle(imgStores);
    for (DataStore store : imgStores) {
      List<TemplateDataStoreVO> sRes = listByTemplateStoreStatus(templateId, store.getId(), State.Ready);
      if (sRes != null && sRes.size() > 0) {
        return sRes.get(0);
      }
    }
  }
  return null;
}

代码示例来源:origin: apache/cloudstack

@Override
public TemplateDataStoreVO findByTemplateZoneStagingDownloadStatus(long templateId, Long zoneId, Status... status) {
  // get all elgible image stores
  List<DataStore> cacheStores = _storeMgr.getImageCacheStores(new ZoneScope(zoneId));
  if (cacheStores != null) {
    for (DataStore store : cacheStores) {
      List<TemplateDataStoreVO> sRes = listByTemplateStoreDownloadStatus(templateId, store.getId(),
          status);
      if (sRes != null && sRes.size() > 0) {
        Collections.shuffle(sRes);
        return sRes.get(0);
      }
    }
  }
  return null;
}

代码示例来源:origin: apache/cloudstack

@Override
public List<TemplateDataStoreVO> listByTemplateZoneDownloadStatus(long templateId, Long zoneId, Status... status) {
  // get all elgible image stores
  List<DataStore> imgStores = _storeMgr.getImageStoresByScope(new ZoneScope(zoneId));
  if (imgStores != null) {
    List<TemplateDataStoreVO> result = new ArrayList<TemplateDataStoreVO>();
    for (DataStore store : imgStores) {
      List<TemplateDataStoreVO> sRes = listByTemplateStoreDownloadStatus(templateId, store.getId(), status);
      if (sRes != null && sRes.size() > 0) {
        result.addAll(sRes);
      }
    }
    return result;
  }
  return null;
}

代码示例来源:origin: apache/cloudstack

@Override
public TemplateDataStoreVO findByTemplateZone(long templateId, Long zoneId, DataStoreRole role) {
  // get all elgible image stores
  List<DataStore> imgStores = null;
  if (role == DataStoreRole.Image) {
    imgStores = _storeMgr.getImageStoresByScope(new ZoneScope(zoneId));
  } else if (role == DataStoreRole.ImageCache) {
    imgStores = _storeMgr.getImageCacheStores(new ZoneScope(zoneId));
  }
  if (imgStores != null) {
    for (DataStore store : imgStores) {
      List<TemplateDataStoreVO> sRes = listByTemplateStore(templateId, store.getId());
      if (sRes != null && sRes.size() > 0) {
        return sRes.get(0);
      }
    }
  }
  return null;
}

代码示例来源:origin: apache/cloudstack

@Override
public List<DataStore> listImageCacheStores(Scope scope) {
  if (scope.getScopeType() != ScopeType.ZONE) {
    s_logger.debug("only support zone wide image cache stores");
    return null;
  }
  List<ImageStoreVO> stores = dataStoreDao.findImageCacheByScope(new ZoneScope(scope.getScopeId()));
  List<DataStore> imageStores = new ArrayList<DataStore>();
  for (ImageStoreVO store : stores) {
    imageStores.add(getImageStore(store.getId()));
  }
  return imageStores;
}

代码示例来源:origin: apache/cloudstack

List<DataStore> imageStores = storeMgr.getImageStoresByScope(new ZoneScope(zoneId));
if (imageStores == null || imageStores.size() == 0) {
  throw new CloudRuntimeException("Unable to find image store to download template " + profile.getTemplate());

代码示例来源:origin: apache/cloudstack

@Override
public TemplateInfo prepareIso(long isoId, long dcId, Long hostId, Long poolId) {
  TemplateInfo tmplt;
  boolean bypassed = false;
  if (_tmplFactory.isTemplateMarkedForDirectDownload(isoId)) {
    tmplt = _tmplFactory.getReadyBypassedTemplateOnPrimaryStore(isoId, poolId, hostId);
    bypassed = true;
  } else {
    tmplt = _tmplFactory.getTemplate(isoId, DataStoreRole.Image, dcId);
  }
  if (tmplt == null || tmplt.getFormat() != ImageFormat.ISO) {
    s_logger.warn("ISO: " + isoId + " does not exist in vm_template table");
    return null;
  }
  if (!bypassed && tmplt.getDataStore() != null && !(tmplt.getDataStore().getTO() instanceof NfsTO)) {
    // if it is s3, need to download into cache storage first
    Scope destScope = new ZoneScope(dcId);
    TemplateInfo cacheData = (TemplateInfo)cacheMgr.createCacheObject(tmplt, destScope);
    if (cacheData == null) {
      s_logger.error("Failed in copy iso from S3 to cache storage");
      return null;
    }
    return cacheData;
  } else {
    return tmplt;
  }
}

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com