Ejemplo n.º 1
0
 /**
  * Update network tag information by marking reported tags as being EXTANT and removing previously
  * EXTANT tags which are no longer reported
  *
  * @param activeNetworks
  */
 public static void updateExtantNetworks(
     ServiceConfiguration cluster, List<NetworkInfoType> activeNetworks) {
   ActiveTags.INSTANCE.update(cluster, activeNetworks);
   /**
    * For each of the reported active network tags ensure that the locally stored extant network
    * state reflects that the network has now been EXTANT in the system (i.e. is no longer PENDING)
    */
   for (NetworkInfoType activeNetInfo : activeNetworks) {
     EntityTransaction tx = Entities.get(NetworkGroup.class);
     try {
       NetworkGroup net = NetworkGroups.lookupByNaturalId(activeNetInfo.getUuid());
       if (net.hasExtantNetwork()) {
         ExtantNetwork exNet = net.extantNetwork();
         if (Reference.State.PENDING.equals(exNet.getState())) {
           LOG.debug(
               "Found PENDING extant network for " + net.getFullName() + " updating to EXTANT.");
           exNet.setState(Reference.State.EXTANT);
         } else {
           LOG.debug(
               "Found "
                   + exNet.getState()
                   + " extant network for "
                   + net.getFullName()
                   + ": skipped.");
         }
       } else {
         LOG.warn(
             "Failed to find extant network for "
                 + net.getFullName()); // TODO:GRZE: likely we should be trying to reclaim tag here
       }
       tx.commit();
     } catch (Exception ex) {
       LOG.debug(ex);
       Logs.extreme().error(ex, ex);
     } finally {
       if (tx.isActive()) tx.rollback();
     }
   }
   /**
    * For each defined network group check to see if the extant network is in the set of active
    * tags and remove it if appropriate.
    *
    * <p>It is appropriate to remove the network when the state of the extant network is {@link
    * Reference.State.RELEASING}.
    *
    * <p>Otherwise, if {@link ActiveTags#INSTANCE#isActive()} is false and:
    *
    * <ol>
    *   <li>The state of the extant network is {@link Reference.State.EXTANT}
    *   <li>The state of the extant network is {@link Reference.State.PENDING} and has exceeded
    *       {@link NetworksGroups#NETWORK_TAG_PENDING_TIMEOUT}
    * </ol>
    *
    * Then the state of the extant network is updated to {@link Reference.State.RELEASING}.
    */
   try {
     final List<NetworkGroup> groups = NetworkGroups.lookupAll(null, null);
     for (NetworkGroup net : groups) {
       final EntityTransaction tx = Entities.get(NetworkGroup.class);
       try {
         net = Entities.merge(net);
         if (net.hasExtantNetwork()) {
           ExtantNetwork exNet = net.getExtantNetwork();
           Integer exNetTag = exNet.getTag();
           if (!ActiveTags.INSTANCE.isActive(exNetTag)) {
             if (Reference.State.EXTANT.equals(exNet.getState())) {
               exNet.setState(Reference.State.RELEASING);
             } else if (Reference.State.PENDING.equals(exNet.getState())
                 && exNet.lastUpdateMillis()
                     > 60L * 1000 * NetworkGroups.NETWORK_TAG_PENDING_TIMEOUT) {
               exNet.setState(Reference.State.RELEASING);
             } else if (Reference.State.RELEASING.equals(exNet.getState())) {
               exNet.teardown();
               Entities.delete(exNet);
               net.setExtantNetwork(null);
             }
           }
         }
         tx.commit();
       } catch (final Exception ex) {
         LOG.debug(ex);
         Logs.extreme().error(ex, ex);
       } finally {
         if (tx.isActive()) tx.rollback();
       }
     }
   } catch (MetadataException ex) {
     LOG.error(ex);
   }
 }