Пример #1
0
 public ExtantNetwork extantNetwork()
     throws NotEnoughResourcesException, TransientEntityException {
   if (!NetworkGroups.networkingConfiguration().hasNetworking()) {
     ExtantNetwork bogusNet = ExtantNetwork.bogus(this);
     if (!this.hasExtantNetwork()) this.setExtantNetwork(bogusNet);
     return bogusNet;
   } else if (!Entities.isPersistent(this)) {
     throw new TransientEntityException(this.toString());
   } else {
     ExtantNetwork exNet = this.getExtantNetwork();
     if (exNet == null) {
       for (Integer i : Numbers.shuffled(NetworkGroups.networkTagInterval())) {
         try {
           Entities.uniqueResult(ExtantNetwork.named(i));
           continue;
         } catch (Exception ex) {
           exNet = ExtantNetwork.create(this, i);
           Entities.persist(exNet);
           this.setExtantNetwork(exNet);
           return this.getExtantNetwork();
         }
       }
       throw new NotEnoughResourcesException(
           "Failed to allocate network tag for network: "
               + this.getFullName()
               + ": no network tags are free.");
     } else {
       return this.getExtantNetwork();
     }
   }
 }
Пример #2
0
 public ExtantNetwork reclaim(Integer i)
     throws NotEnoughResourcesException, TransientEntityException {
   if (!NetworkGroups.networkingConfiguration().hasNetworking()) {
     return ExtantNetwork.bogus(this);
   } else if (!Entities.isPersistent(this)) {
     throw new TransientEntityException(this.toString());
   } else {
     ExtantNetwork exNet = Entities.persist(ExtantNetwork.create(this, i));
     this.setExtantNetwork(exNet);
     return this.getExtantNetwork();
   }
 }
Пример #3
0
  public static synchronized void updateNetworkRangeConfiguration() {
    final AtomicReference<NetworkRangeConfiguration> equalityCheck =
        new AtomicReference<NetworkRangeConfiguration>(null);
    try {
      Transactions.each(
          new ClusterConfiguration(),
          new Callback<ClusterConfiguration>() {

            @Override
            public void fire(final ClusterConfiguration input) {
              NetworkRangeConfiguration comparisonConfig = new NetworkRangeConfiguration();
              comparisonConfig.setUseNetworkTags(input.getUseNetworkTags());
              comparisonConfig.setMinNetworkTag(input.getMinNetworkTag());
              comparisonConfig.setMaxNetworkTag(input.getMaxNetworkTag());
              comparisonConfig.setMinNetworkIndex(input.getMinNetworkIndex());
              comparisonConfig.setMaxNetworkIndex(input.getMaxNetworkIndex());
              Logs.extreme()
                  .debug(
                      "Updating cluster config: "
                          + input.getName()
                          + " "
                          + comparisonConfig.toString());
              if (equalityCheck.compareAndSet(null, comparisonConfig)) {
                Logs.extreme().debug("Initialized cluster config check: " + equalityCheck.get());
              } else {
                NetworkRangeConfiguration currentConfig = equalityCheck.get();
                List<String> errors = Lists.newArrayList();
                if (!currentConfig
                    .getUseNetworkTags()
                    .equals(comparisonConfig.getUseNetworkTags())) {
                  errors.add(
                      input.getName()
                          + " network config mismatch: vlan tagging  "
                          + currentConfig.getUseNetworkTags()
                          + " != "
                          + comparisonConfig.getUseNetworkTags());
                } else if (!currentConfig
                    .getMinNetworkTag()
                    .equals(comparisonConfig.getMinNetworkTag())) {
                  errors.add(
                      input.getName()
                          + " network config mismatch: min vlan tag "
                          + currentConfig.getMinNetworkTag()
                          + " != "
                          + comparisonConfig.getMinNetworkTag());
                } else if (!currentConfig
                    .getMaxNetworkTag()
                    .equals(comparisonConfig.getMaxNetworkTag())) {
                  errors.add(
                      input.getName()
                          + " network config mismatch: max vlan tag "
                          + currentConfig.getMaxNetworkTag()
                          + " != "
                          + comparisonConfig.getMaxNetworkTag());
                } else if (!currentConfig
                    .getMinNetworkIndex()
                    .equals(comparisonConfig.getMinNetworkIndex())) {
                  errors.add(
                      input.getName()
                          + " network config mismatch: min net index "
                          + currentConfig.getMinNetworkIndex()
                          + " != "
                          + comparisonConfig.getMinNetworkIndex());
                } else if (!currentConfig
                    .getMaxNetworkIndex()
                    .equals(comparisonConfig.getMaxNetworkIndex())) {
                  errors.add(
                      input.getName()
                          + " network config mismatch: max net index "
                          + currentConfig.getMaxNetworkIndex()
                          + " != "
                          + comparisonConfig.getMaxNetworkIndex());
                }
              }
            }
          });
    } catch (RuntimeException ex) {
      Logs.extreme().error(ex, ex);
      throw ex;
    } catch (TransactionException ex) {
      LOG.error(ex);
      Logs.extreme().error(ex, ex);
    }

    netConfig = new NetworkRangeConfiguration();
    final AtomicBoolean netTagging = new AtomicBoolean(true);
    try {
      Transactions.each(
          new ClusterConfiguration(),
          new Callback<ClusterConfiguration>() {

            @Override
            public void fire(final ClusterConfiguration input) {
              netTagging.compareAndSet(true, input.getUseNetworkTags());

              netConfig.setMinNetworkTag(
                  Ints.max(netConfig.getMinNetworkTag(), input.getMinNetworkTag()));
              netConfig.setMaxNetworkTag(
                  Ints.min(netConfig.getMaxNetworkTag(), input.getMaxNetworkTag()));

              netConfig.setMinNetworkIndex(
                  Longs.max(netConfig.getMinNetworkIndex(), input.getMinNetworkIndex()));
              netConfig.setMaxNetworkIndex(
                  Longs.min(netConfig.getMaxNetworkIndex(), input.getMaxNetworkIndex()));
            }
          });
      Logs.extreme().debug("Updated network configuration: " + netConfig.toString());
    } catch (final TransactionException ex) {
      Logs.extreme().error(ex, ex);
    }
    netConfig.setUseNetworkTags(netTagging.get());
    final EntityTransaction db = Entities.get(NetworkGroup.class);
    try {
      final List<NetworkGroup> ret = Entities.query(new NetworkGroup());
      for (NetworkGroup group : ret) {
        ExtantNetwork exNet = group.getExtantNetwork();
        if (exNet != null
            && (exNet.getTag() > netConfig.getMaxNetworkTag()
                || exNet.getTag() < netConfig.getMinNetworkTag())) {
          exNet.teardown();
          Entities.delete(exNet);
          group.setExtantNetwork(null);
        }
      }
      db.commit();
    } catch (final Exception ex) {
      Logs.extreme().error(ex, ex);
      LOG.error(ex);
      db.rollback();
    }
  }
Пример #4
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);
   }
 }