コード例 #1
0
 public static void handleOrphan(Cluster cluster, ClusterAddressInfo address) {
   Integer orphanCount = 1;
   orphanCount = orphans.putIfAbsent(address, orphanCount);
   orphanCount = (orphanCount == null) ? 1 : orphanCount;
   orphans.put(address, orphanCount + 1);
   EventRecord.caller(
           ClusterState.class,
           EventType.ADDRESS_STATE,
           "Updated orphaned public ip address: "
               + LogUtil.dumpObject(address)
               + " count="
               + orphanCount)
       .debug();
   if (orphanCount > AddressingConfiguration.getInstance().getMaxKillOrphans()) {
     EventRecord.caller(
             ClusterState.class,
             EventType.ADDRESS_STATE,
             "Unassigning orphaned public ip address: "
                 + LogUtil.dumpObject(address)
                 + " count="
                 + orphanCount)
         .warn();
     try {
       final Address addr = Addresses.getInstance().lookup(address.getAddress());
       if (addr.isPending()) {
         try {
           addr.clearPending();
         } catch (Exception ex) {
         }
       }
       try {
         if (addr.isAssigned() && "0.0.0.0".equals(address.getInstanceIp())) {
           addr.unassign().clearPending();
           if (addr.isSystemOwned()) {
             addr.release();
           }
         } else if (addr.isAssigned() && !"0.0.0.0".equals(address.getInstanceIp())) {
           AsyncRequests.newRequest(new UnassignAddressCallback(address))
               .sendSync(cluster.getConfiguration());
           if (addr.isSystemOwned()) {
             addr.release();
           }
         } else if (!addr.isAssigned() && addr.isAllocated() && addr.isSystemOwned()) {
           addr.release();
         }
       } catch (ExecutionException ex) {
         if (!addr.isAssigned() && addr.isAllocated() && addr.isSystemOwned()) {
           addr.release();
         }
       }
     } catch (InterruptedException ex) {
       Exceptions.maybeInterrupted(ex);
     } catch (NoSuchElementException ex) {
     } finally {
       orphans.remove(address);
     }
   }
 }
コード例 #2
0
 protected static Address lookupOrCreate(
     final Cluster cluster, final ClusterAddressInfo addrInfo) {
   Address addr = null;
   VmInstance vm = null;
   try {
     addr = Addresses.getInstance().lookupDisabled(addrInfo.getAddress());
     LOG.trace("Found address in the inactive set cache: " + addr);
   } catch (final NoSuchElementException e1) {
     try {
       addr = Addresses.getInstance().lookup(addrInfo.getAddress());
       LOG.trace("Found address in the active set cache: " + addr);
     } catch (final NoSuchElementException e) {
     }
   }
   if (addrInfo.hasMapping()) {
     vm =
         Helper.maybeFindVm(
             addr != null ? addr.getInstanceId() : null,
             addrInfo.getAddress(),
             addrInfo.getInstanceIp());
     if ((addr != null) && (vm != null)) {
       Helper.ensureAllocated(addr, vm);
       clearOrphan(addrInfo);
     } else if (addr != null && !addr.isPending() && vm != null && VmStateSet.DONE.apply(vm)) {
       handleOrphan(cluster, addrInfo);
     } else if ((addr != null && addr.isAssigned() && !addr.isPending()) && (vm == null)) {
       handleOrphan(cluster, addrInfo);
     } else if ((addr == null) && (vm != null)) {
       addr =
           new Address(
               Principals.systemFullName(),
               addrInfo.getAddress(),
               vm.getInstanceUuid(),
               vm.getInstanceId(),
               vm.getPrivateAddress());
       clearOrphan(addrInfo);
     } else if ((addr == null) && (vm == null)) {
       addr = new Address(addrInfo.getAddress(), cluster.getPartition());
       handleOrphan(cluster, addrInfo);
     }
   } else {
     if ((addr != null) && addr.isAssigned() && !addr.isPending()) {
       handleOrphan(cluster, addrInfo);
     } else if ((addr != null)
         && !addr.isAssigned()
         && !addr.isPending()
         && addr.isSystemOwned()) {
       try {
         addr.release();
       } catch (final Exception ex) {
         LOG.error(ex);
       }
     } else if ((addr != null) && Address.Transition.system.equals(addr.getTransition())) {
       handleOrphan(cluster, addrInfo);
     } else if (addr == null) {
       addr = new Address(addrInfo.getAddress(), cluster.getPartition());
       Helper.clearVmState(addrInfo);
     }
   }
   return addr;
 }