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); } } }
private boolean transition( State expectedState, State newState, boolean expectedMark, boolean newMark, SplitTransition transition) { this.transition = transition; if (!this.atomicState.compareAndSet(expectedState, newState, expectedMark, newMark)) { throw new IllegalStateException( String.format( "Cannot mark address as %s[%s.%s->%s.%s] when it is %s.%s: %s", transition.getName(), expectedState, expectedMark, newState, newMark, this.atomicState.getReference(), this.atomicState.isMarked(), this.toString())); } EventRecord.caller(this.getClass(), EventType.ADDRESS_STATE, "TOP", this.toString()).info(); try { this.transition.top(); } catch (RuntimeException ex) { LOG.error(ex); Logs.extreme().error(ex, ex); throw ex; } return true; }
public static void write(final String fileName, final Object securityToken) { PEMWriter privOut = null; try { privOut = new PEMWriter(new FileWriter(fileName)); EventRecord.caller(PEMFiles.class, EventType.CERTIFICATE_WRITE, fileName).info(); privOut.writeObject(securityToken); privOut.close(); } catch (final IOException e) { LOG.error(e, e); } }
public Address clearPending() { if (!this.atomicState.isMarked()) { throw new IllegalStateException("Trying to clear an address which is not currently pending."); } else { EventRecord.caller(this.getClass(), EventType.ADDRESS_STATE, "BOTTOM", this.toString()) .info(); try { this.transition.bottom(); } catch (RuntimeException ex) { LOG.error(ex); Logs.extreme().error(ex, ex); } finally { this.transition = this.QUIESCENT; this.atomicState.set(this.atomicState.getReference(), false); } } return this; }