コード例 #1
0
ファイル: AddressUtil.java プロジェクト: chrkl/eucalyptus
 public static void dispatchUnassignAddress(Address address) {
   if (VmInstance.DEFAULT_IP.equals(address.getInstanceAddress())) {
     return;
   }
   try {
     UnassignAddressCallback callback = new UnassignAddressCallback(address);
     Clusters.dispatchClusterEvent(address.getCluster(), callback);
   } catch (Throwable e) {
     LOG.debug(e, e);
   }
 }
コード例 #2
0
ファイル: AddressUtil.java プロジェクト: chrkl/eucalyptus
 private static void handleOrphan(String cluster, Address address) {
   Integer orphanCount = 1;
   orphanCount = orphans.putIfAbsent(address.getName(), orphanCount);
   orphanCount = (orphanCount == null) ? 1 : orphanCount;
   orphans.put(address.getName(), orphanCount + 1);
   LOG.warn("Found orphaned public ip address: " + address + " count=" + orphanCount);
   if (orphanCount > 10) {
     orphans.remove(address.getName());
     Clusters.dispatchClusterEvent(cluster, new UnassignAddressCallback(address));
   }
 }
コード例 #3
0
ファイル: AddressUtil.java プロジェクト: chrkl/eucalyptus
 public static void releaseAddress(final Address currentAddr) {
   if (currentAddr.isAssigned()) {
     try {
       VmInstance vm = VmInstances.getInstance().lookup(currentAddr.getInstanceId());
       unassignAddressFromVm(currentAddr, vm);
     } catch (Throwable e) {
       LOG.debug(e, e);
     }
   }
   currentAddr.release();
 }
コード例 #4
0
ファイル: AddressUtil.java プロジェクト: chrkl/eucalyptus
 public static void clearAddress(Address address) {
   if (!address.isPending()) {
     try {
       markAddressUnassigned(address);
       dispatchUnassignAddress(address);
     } catch (Throwable e1) {
       LOG.debug(e1, e1);
     }
   } else if (Address.UNALLOCATED_USERID.equals(address.getUserId())) {
     address.clean();
   }
 }
コード例 #5
0
ファイル: AddressUtil.java プロジェクト: chrkl/eucalyptus
 private static List<Address> getStoredAddresses(String cluster) {
   EntityWrapper<Address> db = new EntityWrapper<Address>();
   Address clusterAddr = new Address();
   clusterAddr.setCluster(cluster);
   List<Address> addrList = Lists.newArrayList();
   try {
     addrList = db.query(clusterAddr);
     db.commit();
   } catch (Exception e1) {
     db.rollback();
   }
   return addrList;
 }
コード例 #6
0
ファイル: AddressUtil.java プロジェクト: chrkl/eucalyptus
 public static void dispatchAssignAddress(Address address, VmInstance vm) {
   try {
     AssignAddressCallback callback = new AssignAddressCallback(address, vm);
     Clusters.dispatchClusterEvent(address.getCluster(), callback);
   } catch (Throwable e) {
     LOG.debug(e, e);
   }
 }
コード例 #7
0
ファイル: AddressUtil.java プロジェクト: chrkl/eucalyptus
 public static void tryAssignSystemAddress(final VmInstance vm) {
   if (!EucalyptusProperties.disableNetworking) {
     try {
       Address newAddress = AddressUtil.allocateAddresses(vm.getPlacement(), 1).get(0);
       newAddress.setInstanceId(vm.getInstanceId());
       newAddress.setInstanceAddress(vm.getNetworkConfig().getIpAddress());
       AddressUtil.dispatchAssignAddress(newAddress, vm);
     } catch (NotEnoughResourcesAvailable notEnoughResourcesAvailable) {
       LOG.error(
           "Attempt to assign a system address for "
               + vm.getInstanceId()
               + " failed due to lack of addresses.");
     } catch (Exception e) {
       LOG.error(
           "Attempt to assign a system address for "
               + vm.getInstanceId()
               + " failed due to lack of addresses.");
     }
   }
 }
コード例 #8
0
ファイル: AddressUtil.java プロジェクト: chrkl/eucalyptus
 public static Address lookupOrCreate(String cluster, Pair p) {
   Address address;
   try {
     try {
       address = Addresses.getInstance().lookup(p.getLeft());
     } catch (NoSuchElementException e1) {
       address = Addresses.getInstance().lookupDisabled(p.getLeft());
     }
   } catch (NoSuchElementException e) {
     LOG.debug(e);
     address = new Address(p.getLeft(), cluster);
     try {
       VmInstance vm = VmInstances.getInstance().lookupByInstanceIp(p.getRight());
       address.allocate(Component.eucalyptus.name());
       address.setAssigned(vm.getInstanceId(), p.getRight());
     } catch (Exception e1) {
       // TODO: dispatch unassign for unknown address.
     }
     address.init();
   }
   return address;
 }
コード例 #9
0
ファイル: AddressUtil.java プロジェクト: chrkl/eucalyptus
 public static void update(String cluster, List<Pair> ccList) {
   List<String> ccListAddrs =
       Lists.transform(
           ccList,
           new Function<Pair, String>() {
             @Override
             public String apply(Pair p) {
               return p.getLeft();
             }
           });
   for (Pair p : ccList) {
     Address address = AddressUtil.lookupOrCreate(cluster, p);
     try {
       InetAddress addr = Inet4Address.getByName(p.getRight());
       VmInstance vm;
       try {
         vm = VmInstances.getInstance().lookupByInstanceIp(p.getRight());
         if (Address.UNALLOCATED_USERID.equals(address.getUserId())) {
           address.allocate(Component.eucalyptus.name());
         }
         if (!address.isAssigned()) {
           address.setAssigned(vm.getInstanceId(), p.getRight());
         }
         orphans.remove(address.getName());
       } catch (Exception e1) {
         if (!addr.isLoopbackAddress() && !AddressUtil.checkForPendingVm()) {
           AddressUtil.handleOrphan(cluster, address);
         } else {
           orphans.remove(address.getName());
         }
       }
     } catch (UnknownHostException e1) {
       LOG.debug(e1, e1);
       orphans.remove(address.getName());
     }
   }
 }
コード例 #10
0
ファイル: AddressUtil.java プロジェクト: chrkl/eucalyptus
 public static void markAddressUnassigned(Address address) {
   address.unassign();
 }
コード例 #11
0
ファイル: AddressUtil.java プロジェクト: chrkl/eucalyptus
 public static void markAddressAssigned(Address address, VmInstance vm)
     throws EucalyptusCloudException {
   address.assign(vm.getInstanceId(), vm.getNetworkConfig().getIpAddress());
 }
コード例 #12
0
ファイル: AddressUtil.java プロジェクト: chrkl/eucalyptus
 public static boolean initialize(String cluster, List<Pair> ccList) {
   if (AddressUtil.tryInit(cluster)) {
     try {
       List<Address> addrList = getStoredAddresses(cluster);
       List<String> ccListAddrs =
           Lists.transform(
               ccList,
               new Function<Pair, String>() {
                 @Override
                 public String apply(Pair p) {
                   return p.getLeft();
                 }
               });
       for (Address addr : addrList) {
         if (ccListAddrs.contains(addr.getName())) {
           Pair current = checkHasCurrentState(addr.getName(), ccList);
           if (current != null) {
             try {
               VmInstance vm = VmInstances.getInstance().lookupByInstanceIp(current.getRight());
               addr.setAssigned(vm.getInstanceId(), current.getRight());
             } catch (Exception e) {
               addr.doUnassign();
             }
           }
           addr.init();
           ccList.remove(current);
         } else {
           try {
             addr.release();
             Addresses.getInstance().deregister(addr.getName());
           } catch (Throwable e) {
             LOG.debug(e);
           }
         }
       }
       for (Pair current : ccList) {
         Address addr = AddressUtil.lookupOrCreate(cluster, current);
         try {
           VmInstance vm = VmInstances.getInstance().lookupByInstanceIp(current.getRight());
           addr.allocate(Component.eucalyptus.name());
           addr.setAssigned(vm.getInstanceId(), current.getRight());
         } catch (Exception e) {
           addr.doUnassign();
         }
         addr.init();
       }
     } catch (Throwable e) {
       clusterInit.get(cluster).set(false);
     }
     return true;
   } else {
     return false;
   }
 }