Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
Copyright (C) 2013-2014 Dell, Inc ==================================================================== Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. ====================================================================
 
 
 package org.dasein.cloud.azure;
 
 
 import  javax.annotation.Nonnull;
 import  javax.annotation.Nullable;
Displays the available locations for Microsoft Azure services.

Author(s):
George Reese (george.reese@imaginary.com)
Version:
2012.04.1
Since:
2012.04.1
 
 public class AzureLocation implements DataCenterServices {
     static private final Logger logger = Azure.getLogger(AzureLocation.class);
     static private final String LOCATIONS = "/locations";
 
     private Azure provider;
 
     AzureLocation(Azure provider) { this. = provider; }
 
     private transient volatile AzureLocationCapabilities capabilities;
     @Nonnull
     @Override
         if == null ) {
              = new AzureLocationCapabilities();
         }
         return ;
     }
 
     @Override
     public @Nullable DataCenter getDataCenter(@Nonnull String providerDataCenterIdthrows InternalExceptionCloudException {
         ProviderContext ctx = .getContext();
 
         ifctx == null ) {
             throw new AzureConfigException("No context was specified for this request");
         }
         String regionId = ctx.getRegionId();
 
         ifregionId == null ) {
             throw new AzureConfigException("No region was specified for this request");
         }
         forDataCenter dc : listDataCenters(regionId) ) {
             ifdc.getProviderDataCenterId().equals(providerDataCenterId) ) {
                 return dc;
             }
         }
         return null;
     }
 
     @Override
     public @Nonnull String getProviderTermForDataCenter(@Nonnull Locale locale) {
         return "data center";
     }
 
     @Override
     public @Nonnull String getProviderTermForRegion(@Nonnull Locale locale) {
         return "region";
     }
 
     @Override
     public @Nullable Region getRegion(@Nonnull String providerRegionIdthrows InternalExceptionCloudException {
         forRegion region : listRegions() ) {
             ifregion.getProviderRegionId().equals(providerRegionId) ) {
                 return region;
            }
        }
        return null;
    }
    public boolean isSubscribed(AzureService toServicethrows InternalExceptionCloudException {
        ProviderContext ctx = .getContext();
        ifctx == null ) {
            throw new AzureConfigException("No context was specified for this request");
        }
        AzureMethod method = new AzureMethod();
        final String cacheName = "AzureLocation.isSubscribed." + toService;
        Cache<Booleancache = org.dasein.cloud.util.Cache.getInstance(cacheNameBoolean.class.);
        final Iterable<BooleancachedIsSubscribed = cache.get(ctx);
        if (cachedIsSubscribed != null && cachedIsSubscribed.iterator().hasNext()) {
            final Boolean isSubscribed = cachedIsSubscribed.iterator().next();
            if (isSubscribed != null) {
                return isSubscribed;
            }
        }
        Document doc = method.getAsXML(ctx.getAccountNumber(), );
        ifdoc == null ) {
            cache.put(ctx, Collections.singleton(false));
            return false;
        }
        NodeList entries = doc.getElementsByTagName("Location");
        forint i=0; i<entries.getLength(); i++ ) {
            Node entry = entries.item(i);
            ifentry != null ) {
                NodeList attributes = entry.getChildNodes();
                String regionId = null;
                boolean subscribed = false;
                forint j=0; j<attributes.getLength(); j++ ) {
                    Node attribute = attributes.item(j);
                    ifattribute.getNodeName().equalsIgnoreCase("name") && attribute.hasChildNodes() ) {
                        regionId = attribute.getFirstChild().getNodeValue().trim();
                    }
                    else ifattribute.getNodeName().equalsIgnoreCase("availableservices") && attribute.hasChildNodes() ) {
                        NodeList services = attribute.getChildNodes();
                        forint k=0; k<services.getLength(); k++ ) {
                            Node service = services.item(k);
                            ifservice != null && service.getNodeName().equalsIgnoreCase("availableservice") && service.hasChildNodes() ) {
                                String serviceName = service.getFirstChild().getNodeValue().trim();
                                iftoService.toString().equalsIgnoreCase(serviceName) ) {
                                    subscribed = true;
                                    break;
                                }
                            }
                        }
                    }
                }
                ifregionId != null && regionId.equalsIgnoreCase(ctx.getRegionId()) ) {
                    cache.put(ctx, Collections.singleton(subscribed));
                    return subscribed;
                }
            }
        }
        cache.put(ctx, Collections.singleton(false));
        return false;
    }
    @Override
    public @Nonnull Collection<DataCenterlistDataCenters(@Nonnull String providerRegionIdthrows InternalExceptionCloudException {
        Region region = getRegion(providerRegionId);
        ifregion == null ) {
            return Collections.emptyList();
        }
        ProviderContext ctx = .getContext();
        ifctx == null ) {
            throw new AzureConfigException("No context was specified for this request");
        }
        Collection<DataCenterdcs = new ArrayList<DataCenter>();
        DataCenter dc = new DataCenter();
        dc.setActive(true);
        dc.setAvailable(true);
        dc.setName(region.getName());
        dc.setProviderDataCenterId(providerRegionId);
        dc.setRegionId(providerRegionId);
        dcs.add(dc);
        return dcs;
    }
    @Override
    public @Nonnull Collection<RegionlistRegions() throws InternalExceptionCloudException {
        ProviderContext ctx = .getContext();
        ifctx == null ) {
            throw new AzureConfigException("No context was specified for this request");
        }
        Cache<Regioncache = Cache.getInstance("regions"Region.class.new TimePeriod<Minute>(15, .));
        Collection<Regionregions = (Collection<Region>)cache.get(ctx);
        ifregions == null ) {
            regions = new ArrayList<Region>();
            AzureMethod method = new AzureMethod();
            Document doc = method.getAsXML(ctx.getAccountNumber(), );
            ifdoc == null ) {
                return Collections.emptyList();
            }
            NodeList entries = doc.getElementsByTagName("Location");
            forint i=0; i<entries.getLength(); i++ ) {
                Node entry = entries.item(i);
                Region region = toRegion(entry);
                ifregion != null ) {
                    regions.add(region);
                }
            }
            cache.put(ctxregions);
        }
        return regions;
    }
    private @Nullable Region toRegion(@Nullable Node entry) {
        ifentry == null ) {
            return null;
        }
        Region region = new Region();
        NodeList attributes = entry.getChildNodes();
        forint i=0; i<attributes.getLength(); i++ ) {
            Node attribute = attributes.item(i);
            String nodeName = attribute.getNodeName();
            ifnodeName.equalsIgnoreCase("name") && attribute.hasChildNodes() ) {
                region.setProviderRegionId(attribute.getFirstChild().getNodeValue().trim());
            }
            else ifnodeName.equalsIgnoreCase("displayName") && attribute.hasChildNodes() ) {
                region.setName(attribute.getFirstChild().getNodeValue().trim());
            }
        }
        ifregion.getProviderRegionId() == null ) {
            return null;
        }
        ifregion.getName() == null ) {
            region.setName(region.getProviderRegionId());
        }
        region.setActive(true);
        region.setAvailable(true);
        region.setJurisdiction("US");
        return region;
    }
    @Override
    public Collection<ResourcePoollistResourcePools(String providerDataCenterIdthrows InternalExceptionCloudException {
        return Collections.emptyList();
    }
    @Override
    public ResourcePool getResourcePool(String providerResourcePoolIdthrows InternalExceptionCloudException {
        return null;
    }

    
Lists all storage pools

Returns:
all storage pools supported for this cloud in the context region
Throws:
org.dasein.cloud.InternalException an error occurred locally in processing the request
org.dasein.cloud.CloudException an error occurred within the cloud provider or the cloud provider did not approve of the request
    @Nonnull
    @Override
        return Collections.emptyList();
    }
    @Nonnull
    @Override
    public StoragePool getStoragePool(String providerStoragePoolIdthrows InternalExceptionCloudException {
        return null;
    }
    @Nonnull
    @Override
        return Collections.emptyList();
    }
    @Nonnull
    @Override
    public Folder getVMFolder(String providerVMFolderIdthrows InternalExceptionCloudException {
        return null;
    }
New to GrepCode? Check out our FAQ X