本文整理汇总了Java中org.dasein.cloud.util.CacheLevel类的典型用法代码示例。如果您正苦于以下问题:Java CacheLevel类的具体用法?Java CacheLevel怎么用?Java CacheLevel使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
CacheLevel类属于org.dasein.cloud.util包,在下文中一共展示了CacheLevel类的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: listRegions
import org.dasein.cloud.util.CacheLevel; //导入依赖的package包/类
@Override
public Collection<Region> listRegions() throws InternalException, CloudException {
APITrace.begin(getProvider(), "listRegions");
try {
Cache<Region> cache = Cache.getInstance(getProvider(), "regions", Region.class, CacheLevel.CLOUD_ACCOUNT, new TimePeriod<Hour>(10, TimePeriod.HOUR));
Collection<Region> regions = (Collection<Region>)cache.get(getContext());
if( regions != null ) {
return regions;
}
regions = new ArrayList<Region>();
Regions availableRegions = (Regions)DigitalOceanModelFactory.getModel(getProvider(), org.dasein.cloud.digitalocean.models.rest.DigitalOcean.REGIONS);
for( org.dasein.cloud.digitalocean.models.Region s : availableRegions.getRegions() ) {
Region vmp = toRegion(s);
regions.add(vmp);
}
cache.put(getContext(), regions);
return regions;
}
finally {
APITrace.end();
}
}
示例2: getConnectionId
import org.dasein.cloud.util.CacheLevel; //导入依赖的package包/类
/**
* Provides the currently authenticated connection ID, if one exists. If not, it will authenticate and cache that connection ID.
* @return a valid connection ID for executing API operations against Dell ASM
* @throws CloudException an error occurred authentication with Dell ASM
* @throws InternalException an internal error occurred generating the request to Dell ASM
*/
public @Nonnull String getConnectionId() throws CloudException, InternalException {
ProviderContext ctx = provider.getContext();
if( ctx == null ) {
throw new NoContextException();
}
String connectionId = null;
Cache<String> cache = Cache.getInstance(provider, "connectionId", String.class, CacheLevel.CLOUD_ACCOUNT, new TimePeriod<Minute>(50, TimePeriod.MINUTE));
Iterable<String> it = cache.get(ctx);
if( it != null ) {
Iterator<String> iterator = it.iterator();
if( iterator.hasNext() ) {
connectionId = iterator.next();
}
}
if( connectionId == null ) {
connectionId = authenticate(ctx);
cache.put(ctx, Collections.singletonList(connectionId));
}
return connectionId;
}
示例3: listProducts
import org.dasein.cloud.util.CacheLevel; //导入依赖的package包/类
public @Nonnull Iterable<VirtualMachineProduct> listProducts( @Nonnull VirtualMachineProductFilterOptions options, @Nullable Architecture architecture ) throws InternalException, CloudException {
String cacheName = "ALL";
if( architecture != null ) {
cacheName = architecture.name();
}
Cache<VirtualMachineProduct> cache = Cache.getInstance(getProvider(), "products" + cacheName, VirtualMachineProduct.class, CacheLevel.REGION, new TimePeriod<Day>(1, TimePeriod.DAY));
Iterable<VirtualMachineProduct> products = cache.get(getContext());
if( products != null && products.iterator().hasNext() ) {
return products;
}
List<VirtualMachineProduct> list = new ArrayList<VirtualMachineProduct>();
//Perform DigitalOcean query
Sizes availableSizes = (Sizes)DigitalOceanModelFactory.getModel(getProvider(), org.dasein.cloud.digitalocean.models.rest.DigitalOcean.SIZES);
if (availableSizes != null) {
for( Size s : availableSizes.getSizes() ) {
VirtualMachineProduct product = toProduct(s);
if( product != null ) {
list.add(product);
}
}
cache.put(getContext(), list);
}
else {
logger.error("No product could be found, " + getProvider().getCloudName() + " provided no data for their sizes API.");
throw new CloudException("No product could be found.");
}
return list;
}
示例4: listProducts
import org.dasein.cloud.util.CacheLevel; //导入依赖的package包/类
@Override
public Iterable<VirtualMachineProduct> listProducts(VirtualMachineProductFilterOptions options, Architecture architecture) throws InternalException, CloudException {
String cacheName = "productsALL";
if( architecture != null ) {
cacheName = "products" + architecture.name();
}
Cache<VirtualMachineProduct> cache = Cache.getInstance(getProvider(), cacheName, VirtualMachineProduct.class, CacheLevel.REGION, new TimePeriod<Day>(1, TimePeriod.DAY));
Iterable<VirtualMachineProduct> products = cache.get(getContext());
if (products == null) {
List<VirtualMachineProduct> list = new ArrayList<VirtualMachineProduct>();
for (int ram : new int[]{1024, 2048, 4096, 8192, 12288, 16384, 20480, 24576, 28668, 32768}) {
for (int cpuCount : new int[]{1, 2, 3, 4, 5, 6, 7, 8}) {
VirtualMachineProduct product = getProduct(ram + ":" + cpuCount);
if (options != null) {
if (options.matches(product)) {
list.add(product);
}
}
else {
list.add(product);
}
}
}
products = list;
cache.put(getContext(), products);
}
return products;
}
示例5: executeImageSearch
import org.dasein.cloud.util.CacheLevel; //导入依赖的package包/类
private @Nonnull Iterable<MachineImage> executeImageSearch(boolean publicImagesOnly, @Nonnull ImageFilterOptions options) throws CloudException, InternalException {
APITrace.begin(provider, "Image.executeImageSearch");
try {
final String regionId = getContext().getRegionId();
if( regionId == null ) {
throw new CloudException("No region was set for this request");
}
Architecture architecture = options.getArchitecture();
if( architecture != null && !architecture.equals(Architecture.I32) && !architecture.equals(Architecture.I64) ) {
if( !options.isMatchesAny() ) {
return Collections.emptyList();
}
}
String cacheName = "ALL";
if( !options.getWithAllRegions() ) {
cacheName = regionId;
}
Cache<MachineImage> cache = Cache.getInstance(provider, "images" + ( publicImagesOnly ? "pub" : "prv" ) + "-" + cacheName, MachineImage.class, CacheLevel.REGION_ACCOUNT, new TimePeriod<Minute>(5, TimePeriod.MINUTE));
Collection<MachineImage> cachedImages = ( Collection<MachineImage> ) cache.get(getContext());
if( cachedImages != null ) {
return cachedImages;
}
final List<MachineImage> results = new ArrayList<MachineImage>();
final org.dasein.cloud.digitalocean.models.rest.DigitalOcean cmd = publicImagesOnly ? org.dasein.cloud.digitalocean.models.rest.DigitalOcean.IMAGES_PUBLIC : org.dasein.cloud.digitalocean.models.rest.DigitalOcean.IMAGES;
Images images = (Images) getModel(getProvider(), cmd);
int total = images.getTotal();
int page = 1;
while( images.getImages().size() > 0 ) { // let's check >0 just in case
for( Image image : images.getImages() ) {
MachineImage machineImage = toImage(image);
// check if image regions match the requested region if any
if( !options.getWithAllRegions() && image.getRegions().length > 0 && !Arrays.asList(image.getRegions()).contains(getContext().getRegionId()) ) {
total--;
continue;
}
if( machineImage != null && publicImagesOnly == machineImage.isPublic() ) {
if( options.getWithAllRegions() ) {
// explode image to all regions, update total count
int regions = image.getRegions().length;
total += regions - 1;
for( String region : image.getRegions() ) {
machineImage.setProviderRegionId(region);
results.add(machineImage);
machineImage = toImage(image);
}
}
else {
// only add for one region as requested
results.add(machineImage);
}
}
else {
total--; // remove the defective image from the count
}
}
if( total <= 0 || total == results.size() ) {
break;
}
images = (Images) getModel(getProvider(), cmd, ++page);
}
cache.put(getContext(), results);
return results;
}
catch (Throwable e) {
logger.error(e.getMessage());
throw new CloudException(e);
} finally {
APITrace.end();
}
}
示例6: listPossibleDeviceIds
import org.dasein.cloud.util.CacheLevel; //导入依赖的package包/类
@Nonnull
@Override
public Iterable<String> listPossibleDeviceIds(@Nonnull Platform platform) throws InternalException, CloudException {
Cache<String> cache;
if( platform.isWindows() ) {
cache = Cache.getInstance(getProvider(), "windowsDeviceIds", String.class, CacheLevel.CLOUD);
}
else {
cache = Cache.getInstance(getProvider(), "unixDeviceIds", String.class, CacheLevel.CLOUD);
}
Iterable<String> ids = cache.get(getContext());
if( ids == null ) {
ArrayList<String> list = new ArrayList<String>();
if( platform.isWindows() ) {
list.add("hda");
list.add("hdb");
list.add("hdc");
list.add("hdd");
list.add("hde");
list.add("hdf");
list.add("hdg");
list.add("hdh");
list.add("hdi");
list.add("hdj");
}
else {
list.add("/dev/sda");
list.add("/dev/sdb");
list.add("/dev/sdc");
list.add("/dev/sdd");
list.add("/dev/sde");
list.add("/dev/sdf");
list.add("/dev/sdg");
list.add("/dev/sdh");
list.add("/dev/sdi");
}
ids = Collections.unmodifiableList(list);
cache.put(getContext(), ids);
}
return ids;
}
示例7: listPossibleDeviceIds
import org.dasein.cloud.util.CacheLevel; //导入依赖的package包/类
@Nonnull
@Override
public Iterable<String> listPossibleDeviceIds(@Nonnull Platform platform) throws InternalException, CloudException {
Cache<String> cache;
if( platform.isWindows() ) {
cache = Cache.getInstance(getProvider(), "windowsDeviceIds", String.class, CacheLevel.CLOUD);
}
else {
cache = Cache.getInstance(getProvider(), "unixDeviceIds", String.class, CacheLevel.CLOUD);
}
Iterable<String> ids = cache.get(getContext());
if( ids == null ) {
ArrayList<String> list = new ArrayList<String>();
if( platform.isWindows() ) {
list.add("hda");
list.add("hdb");
list.add("hdc");
list.add("hdd");
list.add("hde");
list.add("hdf");
list.add("hdg");
list.add("hdh");
list.add("hdi");
list.add("hdj");
}
else {
list.add("sda1");
list.add("sda2");
list.add("sda3");
list.add("sda4");
list.add("sda5");
list.add("sda6");
list.add("sda7");
list.add("sda8");
list.add("sda9");
}
ids = Collections.unmodifiableList(list);
cache.put(getContext(), ids);
}
return ids;
}
示例8: listDataCenters
import org.dasein.cloud.util.CacheLevel; //导入依赖的package包/类
@Override
public Collection<DataCenter> listDataCenters(String providerRegionId) throws InternalException, CloudException {
APITrace.begin(provider, LIST_DATACENTERS);
try {
Cache<DataCenter> cache = Cache.getInstance(provider, "dataCenters", DataCenter.class, CacheLevel.REGION_ACCOUNT, new TimePeriod<Minute>(15, TimePeriod.MINUTE));
ProviderContext ctx = provider.getContext();
if( ctx == null ) {
logger.error("No context was set for this request");
throw new CloudException("No context was set for this request");
}
Collection<DataCenter> dcs = (Collection<DataCenter>)cache.get(ctx);
if( dcs == null ) {
try {
VirtustreamMethod method = new VirtustreamMethod(provider);
dcs = new ArrayList<DataCenter>();
String obj = method.getString("Site?$filter=Region/RegionID eq '"+providerRegionId+"'", LIST_DATACENTERS);
if (obj != null && obj.length()> 0) {
JSONArray json = new JSONArray(obj);
for (int i=0; i<json.length(); i++) {
DataCenter dc = toDataCenter(json.getJSONObject(i));
if (dc != null) {
dcs.add(dc);
}
}
}
cache.put(ctx, dcs);
}
catch (JSONException e) {
logger.error(e);
throw new InternalException("Unable to parse JSONObject "+e.getMessage());
}
}
return dcs;
}
finally {
APITrace.end();
}
}
示例9: listRegions
import org.dasein.cloud.util.CacheLevel; //导入依赖的package包/类
@Override
public Collection<Region> listRegions() throws InternalException, CloudException {
APITrace.begin(provider, LIST_REGIONS);
try {
Cache<Region> cache = Cache.getInstance(provider, "regions", Region.class, CacheLevel.CLOUD_ACCOUNT, new TimePeriod<Minute>(15, TimePeriod.MINUTE));
ProviderContext ctx = provider.getContext();
if( ctx == null ) {
logger.error("No context was set for this request");
throw new CloudException("No context was set for this request");
}
Collection<Region> regions = (Collection<Region>)cache.get(ctx);
if( regions == null ) {
try {
VirtustreamMethod method = new VirtustreamMethod(provider);
regions = new ArrayList<Region>();
/*String obj = method.getString("Region", LIST_REGIONS);
if (obj != null && obj.length() > 0) {
JSONArray nodes = new JSONArray(obj);
for (int i=0; i<nodes.length(); i++) {
Region r = toRegion(nodes.getJSONObject(i));
if (r != null) {
regions.add(r);
}
}
}*/
// only return regions where we have compute resource available
String obj = method.getString("ResourcePool?$distinct=Hypervisor", LIST_REGIONS);
if (obj != null && obj.length() > 0) {
JSONArray nodes = new JSONArray(obj);
for (int i=0; i<nodes.length(); i++) {
//read out site then get the site's region
JSONObject hypervisor = nodes.getJSONObject(i);
JSONObject site = hypervisor.getJSONObject("Site");
JSONObject region = site.getJSONObject("Region");
Region r = toRegion(region);
if (r != null) {
regions.add(r);
}
}
}
cache.put(ctx, regions);
}
catch (JSONException e) {
logger.error(e);
throw new InternalException("Unable to parse JSONObject "+e.getMessage());
}
}
return regions;
}
finally {
APITrace.end();
}
}
示例10: listDataCenters
import org.dasein.cloud.util.CacheLevel; //导入依赖的package包/类
@Override
public @Nonnull Collection<DataCenter> listDataCenters(@Nonnull String providerRegionId) throws InternalException, CloudException {
APITrace.begin(provider, "listDataCenters");
try {
if( logger.isTraceEnabled() ) {
logger.trace("ENTER: " + DataCenters.class.getName() + ".listDataCenters(" + providerRegionId + ")");
}
try {
Region region = getRegion(providerRegionId);
if( region == null ) {
logger.warn("Attempt to fetch data centers for non-existent region: " + providerRegionId);
throw new CloudException("No such region: " + providerRegionId);
}
ProviderContext ctx = provider.getContext();
if( ctx == null ) {
logger.warn("Attempt to fetch data centers for " + providerRegionId + " with no context");
throw new NoContextException();
}
Cache<DataCenter> cache = Cache.getInstance(provider, "dataCenters", DataCenter.class, CacheLevel.REGION_ACCOUNT, new TimePeriod<Day>(1, TimePeriod.DAY));
Collection<DataCenter> dcList = (Collection<DataCenter>)cache.get(ctx);
if( dcList != null ) {
if( logger.isDebugEnabled() ) {
logger.debug("listDataCenters(" + providerRegionId + ")=" + dcList);
}
return dcList;
}
ArrayList<DataCenter> dataCenters = new ArrayList<DataCenter>();
DataCenter dc = new DataCenter();
dc.setActive(true);
dc.setAvailable(true);
dc.setName(region.getName() + " (DC)");
dc.setProviderDataCenterId(region.getProviderRegionId());
dc.setRegionId(region.getProviderRegionId());
dataCenters.add(dc);
cache.put(ctx, dataCenters);
if( logger.isDebugEnabled() ) {
logger.debug("listDataCenters(" + providerRegionId + ")=" + dataCenters);
}
return dataCenters;
}
finally {
if( logger.isTraceEnabled() ) {
logger.trace("EXIT: " + DataCenters.class.getName() + ".listDataCenters()");
}
}
}
finally {
APITrace.end();
}
}
示例11: listRegions
import org.dasein.cloud.util.CacheLevel; //导入依赖的package包/类
@Override
public Collection<Region> listRegions() throws InternalException, CloudException {
APITrace.begin(provider, "listRegions");
try {
if( logger.isTraceEnabled() ) {
logger.trace("ENTER: " + DataCenters.class.getName() + ".listRegions()");
}
try {
ProviderContext ctx = provider.getContext();
if( ctx == null ) {
logger.warn("Attempt to fetch regions with no context");
throw new NoContextException();
}
Cache<Region> cache = Cache.getInstance(provider, "regions", Region.class, CacheLevel.CLOUD_ACCOUNT, new TimePeriod<Hour>(10, TimePeriod.HOUR));
Collection<Region> regions = (Collection<Region>)cache.get(ctx);
if( regions != null ) {
if( logger.isDebugEnabled() ) {
logger.debug("listRegions()=" + regions);
}
return regions;
}
regions = new ArrayList<Region>();
Region region = new Region();
region.setActive(true);
region.setAvailable(true);
String ctry = Locale.getDefault().getCountry();
if( ctry == null || ctry.equals("") ) {
ctry = "US";
}
try {
Jurisdiction.valueOf(ctry);
}
catch( Throwable ignore ) {
ctry = "US";
}
region.setJurisdiction(ctry);
region.setName(ctry);
region.setProviderRegionId(ctry);
regions.add(region);
cache.put(ctx, regions);
if( logger.isDebugEnabled() ) {
logger.debug("listRegions()=" + regions);
}
return regions;
}
finally {
if( logger.isTraceEnabled() ) {
logger.trace("EXIT: " + DataCenters.class.getName() + ".listRegions()");
}
}
}
finally {
APITrace.end();
}
}