@Override
 public void fireEvent(final ClockTick event) {
   if (Topology.isEnabledLocally(AutoScaling.class) && Bootstrap.isOperational()) {
     try {
       ZoneMonitor.checkZones();
     } catch (Exception ex) {
       logger.error(ex, ex);
     }
   }
 }
Exemplo n.º 2
0
 @Override
 public void handleUpstream(final ChannelHandlerContext ctx, final ChannelEvent e)
     throws Exception {
   if (!Bootstrap.isFinished()) {
     // TODO:GRZE: do nothing for the moment, not envouh info here.
     //        throw new ServiceNotReadyException( "System has not yet completed booting." );
     ctx.sendUpstream(e);
   } else {
     ctx.sendUpstream(e);
   }
 }
Exemplo n.º 3
0
 @SuppressWarnings("UnnecessaryQualifiedReference")
 @Override
 public void fireEvent(final ClockTick event) {
   if (counter++ % intervalTicks == 0
       && Topology.isEnabledLocally(Eucalyptus.class)
       && Hosts.isCoordinator()
       && Bootstrap.isOperational()
       && !Databases.isVolatile()) {
     requestNetworkInfoBroadcast();
   }
 }
 /**
  * This resolver works when it is: 1. Enabled 2. The query is absolute 3. The name/address is not
  * in a Eucalyptus controlled subdomain
  *
  * @see com.eucalyptus.util.dns.DnsResolvers.DnsResolver#checkAccepts(Record, org.xbill.DNS.Name,
  *     InetAddress)
  */
 @Override
 public boolean checkAccepts(Record query, InetAddress source) {
   if (!Bootstrap.isOperational() || !enabled) {
     return false;
   } else if ((RequestType.A.apply(query) || RequestType.AAAA.apply(query))
       && query.getName().isAbsolute()
       && !DomainNames.isSystemSubdomain(query.getName())) {
     return true;
   } else if (RequestType.PTR.apply(query)
       && !Subnets.isSystemManagedAddress(
           DomainNameRecords.inAddrArpaToInetAddress(query.getName()))) {
     return true;
   }
   return false;
 }
Exemplo n.º 5
0
 public static SetResponse findRecords(
     final Message response, final Record queryRecord, final InetAddress source) {
   final Name name = queryRecord.getName();
   final int type = queryRecord.getType();
   try {
     if (!enabled || !Bootstrap.isOperational()) {
       return SetResponse.ofType(SetResponse.UNKNOWN);
     } else {
       final Iterable<DnsResolver> resolverList = DnsResolvers.resolversFor(queryRecord, source);
       LOG.debug("DnsResolvers.findRecords(): resolvers for " + name + " are: " + resolverList);
       if (Iterables.isEmpty(resolverList)) {
         return SetResponse.ofType(SetResponse.UNKNOWN);
       } else {
         return DnsResolvers.lookupRecords(response, queryRecord, source);
       }
     }
   } catch (final Exception ex) {
     LOG.error(ex);
     LOG.trace(ex, ex);
   }
   return SetResponse.ofType(SetResponse.UNKNOWN);
 }
  @Override
  public void fireEvent(ClockTick event) {
    if (!(Bootstrap.isFinished() && Topology.isEnabledLocally(Eucalyptus.class))) return;

    /// check the state of emis
    final List<ImageInfo> partitionedImages = getPartitionedImages();
    final List<ImageInfo> newConversion =
        Lists.newArrayList(
            Collections2.filter(
                partitionedImages,
                new Predicate<ImageInfo>() {
                  @Override
                  public boolean apply(ImageInfo arg0) {
                    if (arg0 instanceof MachineImageInfo) {
                      final MachineImageInfo image = (MachineImageInfo) arg0;
                      return ImageMetadata.State.pending_conversion.equals(image.getState())
                          && (image.getImageConversionId() == null
                              || image.getImageConversionId().length() <= 0);
                    } else return false;
                  }
                }));

    /// check the task id
    final List<ImageInfo> inConversion =
        Lists.newArrayList(
            Collections2.filter(
                partitionedImages,
                new Predicate<ImageInfo>() {
                  @Override
                  public boolean apply(ImageInfo arg0) {
                    if (arg0 instanceof MachineImageInfo) {
                      final MachineImageInfo image = (MachineImageInfo) arg0;
                      return (image.getImageConversionId() != null
                              && image.getImageConversionId().length() > 0)
                          && (ImageMetadata.State.pending_conversion.equals(image.getState())
                              || ImageMetadata.State.deregistered_cleanup.equals(image.getState()));
                    } else return false;
                  }
                }));

    if (!Topology.isEnabled(Imaging.class)
        && !(newConversion.isEmpty() && inConversion.isEmpty())) {
      LOG.warn("To convert partitioned images, Imaging Service should be enabled");
      return;
    }
    if (!Topology.isEnabled(ObjectStorage.class) && !newConversion.isEmpty()) {
      LOG.warn("To convert partitioned images, Object Storage Service should be enabled");
      return;
    }

    try {
      createBuckets(newConversion);
      convertImages(newConversion);
    } catch (final Exception ex) {
      LOG.error("Failed to convert images", ex);
    }

    try {
      checkConversion(inConversion);
    } catch (final Exception ex) {
      LOG.error("Failed to check and update images in conversion", ex);
    }

    // clean up objects and buckets of any deregistered images
    final List<ImageInfo> cleanupImages =
        Lists.newArrayList(
            Collections2.filter(
                this.getDeregisteredCleanupImages(),
                new Predicate<ImageInfo>() {
                  @Override
                  public boolean apply(ImageInfo arg0) {
                    // the conversion task may be still in progress by workers
                    return !(ImageMetadata.State.pending_conversion.equals(arg0.getLastState()));
                  }
                }));
    try {
      cleanupBuckets(cleanupImages, true);
    } catch (final Exception ex) {
      LOG.error("Failed to clean up objects and bucket of deregistered images", ex);
    }

    try {
      this.updateTags(
          Lists.transform(
              partitionedImages,
              new Function<ImageInfo, String>() {
                @Override
                public String apply(ImageInfo arg0) {
                  return arg0.getDisplayName();
                }
              }));
    } catch (final Exception ex) {
      LOG.error("Failed to tag images and instances in conversion", ex);
    }
  }
  @Override
  public void fireEvent(final Hertz event) {
    final long defaultPollIntervalSeconds = TimeUnit.MINUTES.toSeconds(DEFAULT_POLL_INTERVAL_MINS);
    if (!Bootstrap.isOperational()
        || !BootstrapArgs.isCloudController()
        || !event.isAsserted(defaultPollIntervalSeconds)) {
      return;
    } else {
      if (DEFAULT_POLL_INTERVAL_MINS >= 1) {
        COLLECTION_INTERVAL_TIME_MS =
            ((int) TimeUnit.MINUTES.toMillis(DEFAULT_POLL_INTERVAL_MINS) / 2);
      } else {
        COLLECTION_INTERVAL_TIME_MS = 0;
      }

      if (COLLECTION_INTERVAL_TIME_MS == 0 || HISTORY_SIZE > 15 || HISTORY_SIZE < 1) {
        LOG.debug("The instance usage report is disabled");
      } else if (COLLECTION_INTERVAL_TIME_MS <= MAX_WRITE_INTERVAL_MS) {

        try {
          if (event.isAsserted(defaultPollIntervalSeconds)) {
            if (Bootstrap.isFinished() && Hosts.isCoordinator()) {
              CloudWatchHelper.DefaultInstanceInfoProvider.refresh();
              for (final ServiceConfiguration ccConfig :
                  Topology.enabledServices(ClusterController.class)) {
                final String ccHost = ccConfig.getHostName();
                if (busyHosts.replace(ccHost, false, true)
                    || busyHosts.putIfAbsent(ccHost, true) == null) {
                  Threads.lookup(Reporting.class, DescribeSensorsListener.class)
                      .submit(
                          new Callable<Object>() {

                            @Override
                            public Object call() throws Exception {
                              final ExecutorService executorService =
                                  Threads.lookup(
                                          Reporting.class,
                                          DescribeSensorsListener.class,
                                          "response-processing")
                                      .limitTo(4);
                              final long startTime = System.currentTimeMillis();
                              try {
                                final List<String> allInstanceIds =
                                    VmInstances.listWithProjection(
                                        VmInstances.instanceIdProjection(),
                                        VmInstance.criterion(VmState.RUNNING),
                                        VmInstance.zoneCriterion(ccConfig.getPartition()),
                                        VmInstance.nonNullNodeCriterion());
                                final Iterable<List<String>> processInts =
                                    Iterables.partition(allInstanceIds, SENSOR_QUERY_BATCH_SIZE);
                                for (final List<String> instIds : processInts) {
                                  final ArrayList<String> instanceIds = Lists.newArrayList(instIds);
                                  /**
                                   * Here this is hijacking the sensor callback in order to control
                                   * the thread of execution used when firing
                                   */
                                  final DescribeSensorCallback msgCallback =
                                      new DescribeSensorCallback(
                                          HISTORY_SIZE, COLLECTION_INTERVAL_TIME_MS, instanceIds) {
                                        @Override
                                        public void fireException(Throwable e) {}

                                        @Override
                                        public void fire(DescribeSensorsResponse msg) {}
                                      };
                                  /**
                                   * Here we actually get the future reference to the result and on
                                   * a response processing thread, invoke .fire().
                                   */
                                  final DescribeSensorsResponse response =
                                      AsyncRequests.newRequest(msgCallback)
                                          .dispatch(ccConfig)
                                          .get();
                                  executorService.submit(
                                      new Runnable() {
                                        @Override
                                        public void run() {
                                          try {
                                            new DescribeSensorCallback(
                                                    HISTORY_SIZE,
                                                    COLLECTION_INTERVAL_TIME_MS,
                                                    instanceIds)
                                                .fire(response);
                                          } catch (Exception e) {
                                            Exceptions.maybeInterrupted(e);
                                          }
                                        }
                                      });
                                }
                              } finally {
                                /** Only and finally set the busy bit back to false. */
                                busyHosts.put(ccHost, false);
                                LOG.debug(
                                    "Sensor polling for "
                                        + ccHost
                                        + " took "
                                        + (System.currentTimeMillis() - startTime)
                                        + "ms");
                              }
                              return null;
                            }
                          });
                } else {
                  LOG.warn(
                      "Skipping sensors polling for " + ccHost + ", previous poll not complete.");
                }
              }
            }
          }
        } catch (Exception ex) {
          LOG.error("Unable to listen for describe sensors events", ex);
        }

      } else {
        LOG.error(
            "DEFAULT_POLL_INTERVAL_MINS : "
                + DEFAULT_POLL_INTERVAL_MINS
                + " must be less than 1440 minutes");
      }
    }
  }
  @Override
  public void fireEvent(final ClockTick event) {
    if (Bootstrap.isFinished() && Hosts.isCoordinator()) {

      final List<ResourceAvailabilityEvent> resourceAvailabilityEvents = Lists.newArrayList();
      final Map<ResourceAvailabilityEvent.ResourceType, AvailabilityAccumulator> availabilities =
          Maps.newEnumMap(ResourceAvailabilityEvent.ResourceType.class);
      final Iterable<VmType> vmTypes = Lists.newArrayList(VmTypes.list());
      for (final Cluster cluster : Clusters.getInstance().listValues()) {
        availabilities.put(Core, new AvailabilityAccumulator(VmType.SizeProperties.Cpu));
        availabilities.put(Disk, new AvailabilityAccumulator(VmType.SizeProperties.Disk));
        availabilities.put(Memory, new AvailabilityAccumulator(VmType.SizeProperties.Memory));

        for (final VmType vmType : vmTypes) {
          final ResourceState.VmTypeAvailability va =
              cluster.getNodeState().getAvailability(vmType.getName());

          resourceAvailabilityEvents.add(
              new ResourceAvailabilityEvent(
                  Instance,
                  new ResourceAvailabilityEvent.Availability(
                      va.getMax(),
                      va.getAvailable(),
                      Lists.<ResourceAvailabilityEvent.Tag>newArrayList(
                          new ResourceAvailabilityEvent.Dimension(
                              "availabilityZone", cluster.getPartition()),
                          new ResourceAvailabilityEvent.Dimension("cluster", cluster.getName()),
                          new ResourceAvailabilityEvent.Type("vm-type", vmType.getName())))));

          for (final AvailabilityAccumulator availability : availabilities.values()) {
            availability.total =
                Math.max(
                    availability.total, va.getMax() * availability.valueExtractor.apply(vmType));
            availability.available =
                Math.max(
                    availability.available,
                    va.getAvailable() * availability.valueExtractor.apply(vmType));
          }
        }

        for (final AvailabilityAccumulator availability : availabilities.values()) {
          availability.rollUp(
              Lists.<ResourceAvailabilityEvent.Tag>newArrayList(
                  new ResourceAvailabilityEvent.Dimension(
                      "availabilityZone", cluster.getPartition()),
                  new ResourceAvailabilityEvent.Dimension("cluster", cluster.getName())));
        }
      }

      for (final Map.Entry<ResourceAvailabilityEvent.ResourceType, AvailabilityAccumulator> entry :
          availabilities.entrySet()) {
        resourceAvailabilityEvents.add(
            new ResourceAvailabilityEvent(entry.getKey(), entry.getValue().availabilities));
      }

      for (final ResourceAvailabilityEvent resourceAvailabilityEvent : resourceAvailabilityEvents)
        try {
          ListenerRegistry.getInstance().fireEvent(resourceAvailabilityEvent);
        } catch (Exception ex) {
          logger.error(ex, ex);
        }
    }
  }