public static DescribeServicesResponseType describeService(final DescribeServicesType request) {
    final DescribeServicesResponseType reply = request.getReply();
    Topology.touch(request);
    if (request.getServices().isEmpty()) {
      final ComponentId compId =
          (request.getByServiceType() != null)
              ? ComponentIds.lookup(request.getByServiceType().toLowerCase())
              : Empyrean.INSTANCE;
      final boolean showEventStacks = Boolean.TRUE.equals(request.getShowEventStacks());
      final boolean showEvents = Boolean.TRUE.equals(request.getShowEvents()) || showEventStacks;

      final Function<ServiceConfiguration, ServiceStatusType> transformToStatus =
          ServiceConfigurations.asServiceStatus(showEvents, showEventStacks);
      final List<Predicate<ServiceConfiguration>> filters =
          new ArrayList<Predicate<ServiceConfiguration>>() {
            {
              if (request.getByPartition() != null) {
                Partitions.exists(request.getByPartition());
                this.add(Filters.partition(request.getByPartition()));
              }
              if (request.getByState() != null) {
                final Component.State stateFilter =
                    Component.State.valueOf(request.getByState().toUpperCase());
                this.add(Filters.state(stateFilter));
              }
              if (!request.getServiceNames().isEmpty()) {
                this.add(Filters.name(request.getServiceNames()));
              }
              this.add(Filters.host(request.getByHost()));
              this.add(
                  Filters.listAllOrInternal(
                      request.getListAll(),
                      request.getListUserServices(),
                      request.getListInternal()));
            }
          };
      final Predicate<Component> componentFilter = Filters.componentType(compId);
      final Predicate<ServiceConfiguration> configPredicate = Predicates.and(filters);

      List<ServiceConfiguration> replyConfigs = Lists.newArrayList();
      for (final Component comp : Components.list()) {
        if (componentFilter.apply(comp)) {
          Collection<ServiceConfiguration> acceptedConfigs =
              Collections2.filter(comp.services(), configPredicate);
          replyConfigs.addAll(acceptedConfigs);
        }
      }
      ImmutableList<ServiceConfiguration> sortedReplyConfigs =
          ServiceOrderings.defaultOrdering().immutableSortedCopy(replyConfigs);
      final Collection<ServiceStatusType> transformedReplyConfigs =
          Collections2.transform(sortedReplyConfigs, transformToStatus);
      reply.getServiceStatuses().addAll(transformedReplyConfigs);
    } else {
      for (ServiceId s : request.getServices()) {
        reply.getServiceStatuses().add(TypeMappers.transform(s, ServiceStatusType.class));
      }
    }
    return reply;
  }
Esempio n. 2
0
 @Nullable
 @Override
 public ActivityTypeDetail apply(@Nullable final ActivityType activityType) {
   return activityType == null
       ? null
       : new ActivityTypeDetail()
           .withConfiguration(
               new ActivityTypeConfiguration()
                   .withDefaultTaskList(
                       new TaskList().withName(activityType.getDefaultTaskList()))
                   .withDefaultTaskHeartbeatTimeout(
                       timeout(activityType.getDefaultTaskHeartbeatTimeout()))
                   .withDefaultTaskScheduleToCloseTimeout(
                       timeout(activityType.getDefaultTaskScheduleToCloseTimeout()))
                   .withDefaultTaskScheduleToStartTimeout(
                       timeout(activityType.getDefaultTaskScheduleToStartTimeout()))
                   .withDefaultTaskStartToCloseTimeout(
                       timeout(activityType.getDefaultTaskStartToCloseTimeout())))
           .withTypeInfo(TypeMappers.transform(activityType, ActivityTypeInfo.class));
 }
  @Override
  public void onResource(final RestrictedType resource, final String action) {
    EuarePolicyContext.clearContext();

    if (resource != null) {
      if (accepted.contains(resource.getClass())
          || (!rejected.contains(resource.getClass())
              && Account.class.isAssignableFrom(resource.getClass())))
        try {
          EuarePolicyContext.setEuarePolicyContextResource(
              TypeMappers.transform(resource, EuarePolicyContextResource.class));
          accepted.add(resource.getClass());
        } catch (IllegalArgumentException e) {
          rejected.add(resource.getClass());
          Logs.exhaust()
              .info(
                  "Policy context not set for resource type: "
                      + resource.getClass().getSimpleName());
        }
    }
  }
 public static DestroyServiceResponseType destroyService(final DestroyServiceType request)
     throws Exception {
   DestroyServiceResponseType reply = request.getReply();
   for (final ServiceId serviceInfo : request.getServices()) {
     try {
       final ServiceConfiguration service =
           TypeMappers.transform(serviceInfo, ServiceConfiguration.class);
       if (service.isVmLocal()) {
         try {
           Topology.destroy(service).get();
         } catch (final IllegalStateException ex) {
           LOG.error(ex, ex);
         }
       }
       reply.getServices().add(serviceInfo);
     } catch (final Exception ex) {
       LOG.error(ex);
       Logs.extreme().debug(ex, ex);
     }
   }
   return reply;
 }
  @SuppressWarnings("unchecked")
  @Override
  public void onResource(final PolicyResourceInfo resource, final String action) {
    EuarePolicyContext.clearContext();

    if (resource != null && RestrictedType.class.isAssignableFrom(resource.getResourceClass())) {
      if (accepted.contains(resource.getResourceClass())
          || (!rejected.contains(resource.getResourceClass())
              && EuareAccount.class.isAssignableFrom(resource.getResourceClass())))
        try {
          EuarePolicyContext.setEuarePolicyContextResource(
              TypeMappers.transform(
                  resource.getResourceObject(), EuarePolicyContextResource.class));
          accepted.add((Class<? extends RestrictedType>) resource.getResourceClass());
        } catch (IllegalArgumentException e) {
          rejected.add((Class<? extends RestrictedType>) resource.getResourceClass());
          Logs.exhaust()
              .info(
                  "Policy context not set for resource type: "
                      + resource.getResourceClass().getSimpleName());
        }
    }
  }
 public static DisableServiceResponseType disableService(final DisableServiceType request)
     throws Exception {
   final DisableServiceResponseType reply = request.getReply();
   for (final ServiceId serviceInfo : request.getServices()) {
     try {
       final Component comp = Components.lookup(serviceInfo.getType());
       final ServiceConfiguration service =
           TypeMappers.transform(serviceInfo, ServiceConfiguration.class);
       if (service.isVmLocal()) {
         try {
           Topology.disable(service).get();
           reply.getServices().add(serviceInfo);
         } catch (final IllegalStateException ex) {
           LOG.error(ex, ex);
           throw ex;
         }
       }
     } catch (final NoSuchElementException ex) {
       LOG.error(ex, ex);
       throw ex;
     }
   }
   return reply;
 }