Example #1
0
 private void fireUsageEvent(
     final OwnerFullName ownerFullName,
     final Supplier<EventActionInfo<AddressAction>> actionInfoSupplier) {
   if (!Principals.isFakeIdentityAccountNumber(ownerFullName.getAccountNumber())) {
     try {
       ListenerRegistry.getInstance()
           .fireEvent(
               AddressEvent.with(
                   getNaturalId(),
                   getDisplayName(),
                   ownerFullName,
                   Accounts.lookupAccountById(ownerFullName.getAccountNumber()).getName(),
                   actionInfoSupplier.get()));
     } catch (final Exception e) {
       LOG.error(e, e);
     }
   }
 }
Example #2
0
 static void fireUsageEvent(final Volume volume, final EventActionInfo<VolumeAction> actionInfo) {
   try {
     ListenerRegistry.getInstance()
         .fireEvent(
             VolumeEvent.with(
                 actionInfo,
                 volume.getNaturalId(),
                 volume.getDisplayName(),
                 volume.getSize(),
                 volume.getOwner(),
                 volume.getPartition()));
   } catch (final Throwable e) {
     LOG.error(
         "Error creating/inserting reporting event "
             + (actionInfo == null ? "null" : actionInfo.getAction().toString())
             + " for volume "
             + (volume == null ? "null" : volume.getDisplayName()),
         e);
   }
 }
  @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);
        }
    }
  }