private void enforceColocation(final boolean requireEnabled) throws ServiceStateException {
   if (!ComponentIds.lookup(this.component).isManyToOnePartition()
       && !Topology.isEnabledLocally(Eucalyptus.class)
       && (!requireEnabled || Topology.isEnabledLocally(component))) {
     throw new ServiceStateException(
         "The "
             + ComponentIds.lookup(component).name()
             + " service depends upon a locally ENABLED "
             + ComponentIds.lookup(Eucalyptus.class).name());
   }
 }
Example #2
0
 @Override
 public void handleUpstream(final ChannelHandlerContext ctx, final ChannelEvent e)
     throws Exception {
   final MappingHttpRequest request = MappingHttpMessage.extractMessage(e);
   final BaseMessage msg = BaseMessage.extractMessage(e);
   if (msg != null) {
     try {
       final Class<? extends ComponentId> compClass = ComponentMessages.lookup(msg);
       ComponentId compId = ComponentIds.lookup(compClass);
       if (compId.isAlwaysLocal() || Topology.isEnabledLocally(compClass)) {
         ctx.sendUpstream(e);
       } else {
         Handlers.sendRedirect(ctx, e, compClass, request);
       }
     } catch (final NoSuchElementException ex) {
       LOG.warn(
           "Failed to find reverse component mapping for message type: " + msg.getClass());
       ctx.sendUpstream(e);
     } catch (final Exception ex) {
       Logs.extreme().error(ex, ex);
       ctx.sendUpstream(e);
     }
   } else {
     ctx.sendUpstream(e);
   }
 }
  public static ServiceConfiguration findService(final String name) {
    checkParam(name, notNullValue());
    Predicate<ServiceConfiguration> nameOrFullName =
        new Predicate<ServiceConfiguration>() {

          @Override
          public boolean apply(ServiceConfiguration input) {
            return name.equals(input.getName()) || name.equals(input.getFullName().toString());
          }
        };
    for (final ComponentId compId : ComponentIds.list()) {
      ServiceConfiguration a;
      try {
        return Iterables.find(Components.lookup(compId).services(), nameOrFullName);
      } catch (NoSuchElementException ex) {
        if (compId.isRegisterable()) {
          try {
            return ServiceConfigurations.lookupByName(compId.getClass(), name);
          } catch (Exception ex1) {
          }
        }
      }
    }
    throw new NoSuchElementException("Failed to lookup service named: " + name);
  }
  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;
  }
 @Override
 public FullName getFullName() {
   return FullName.create
       .vendor("euca")
       .region(ComponentIds.lookup(Eucalyptus.class).name())
       .namespace(this.getOwnerAccountNumber())
       .relativeId("image", this.getDisplayName());
 }
Example #6
0
 @Override
 public FullName getFullName() {
   return FullName.create
       .vendor("euca")
       .region(ComponentIds.lookup(ClusterController.class).name())
       .namespace(this.getPartition())
       .relativeId("public-address", this.getName());
 }
Example #7
0
 @Override
 public boolean load() throws Exception {
   for (final ComponentId comp : ComponentIds.list()) {
     Pipelines.internalPipelines.add(new InternalQueryPipeline(comp));
     Pipelines.internalPipelines.add(new InternalSoapPipeline(comp));
   }
   return true;
 }
Example #8
0
 private static FilteredPipeline findAccepting(final HttpRequest request) {
   final FilteredPipeline candidate = null;
   for (final FilteredPipeline f : pipelines) {
     if (f.checkAccepts(request)) {
       return f;
     }
   }
   if (request.getHeader(HttpHeaders.Names.HOST).contains("amazonaws.com")
       || request.getHeader(HttpHeaders.Names.HOST).contains(subDomain.get())) {
     String hostHeader = request.getHeader(HttpHeaders.Names.HOST);
     LOG.debug("Trying to intercept request for " + hostHeader);
     for (final FilteredPipeline f : pipelines) {
       if (Ats.from(f).has(ComponentPart.class)) {
         Class<? extends ComponentId> compIdClass = Ats.from(f).get(ComponentPart.class).value();
         ComponentId compId = ComponentIds.lookup(compIdClass);
         if (Ats.from(compIdClass).has(PublicService.class)) {
           if (request.getHeaderNames().contains("SOAPAction")
               && f.addHandlers(Channels.pipeline()).get(SoapHandler.class) == null) {
             continue; // Skip pipeline which doesn't handle SOAP for this SOAP request
           } else if (!request.getHeaderNames().contains("SOAPAction")
               && f.addHandlers(Channels.pipeline()).get(SoapHandler.class) != null) {
             continue; // Skip pipeline which handles SOAP for this non-SOAP request
           }
           LOG.debug("Maybe intercepting: " + hostHeader + " using " + f.getClass());
           if (Ats.from(compIdClass).has(AwsServiceName.class)
               && request
                   .getHeader(HttpHeaders.Names.HOST)
                   .matches(
                       "[\\w\\.-_]*" + compId.getAwsServiceName() + "\\.\\w+\\.amazonaws.com")) {
             return f; // Return pipeline which can handle the request for
                       // ${service}.${region}.amazonaws.com
           } else if (request
               .getHeader(HttpHeaders.Names.HOST)
               .matches("[\\w\\.-_]*" + compId.name() + "\\." + subDomain.get())) {
             return f; // Return pipeline which can handle the request for
                       // ${service}.${system.dns.dnsdomain}
           }
         }
       }
     }
   }
   if (candidate == null) {
     for (final FilteredPipeline f : internalPipelines) {
       if (f.checkAccepts(request)) {
         return f;
       }
     }
   }
   return candidate;
 }
    public DescribeServicesResponseType user(final DescribeServicesType request) {
      final DescribeServicesResponseType reply = request.getReply();
      /**
       * Only show public services to normal users. Allow for filtering by component and state w/in
       * that set.
       */
      final List<Predicate<ServiceConfiguration>> filters =
          new ArrayList<Predicate<ServiceConfiguration>>() {
            {
              this.add(Filters.publicService());
              if (request.getByPartition() != null) {
                this.add(Filters.partition(request.getByPartition()));
              }
              if (request.getByState() != null) {
                this.add(
                    Filters.state(Component.State.valueOf(request.getByState().toUpperCase())));
              }
            }
          };
      final Predicate<Component> componentFilter =
          (Predicate<Component>)
              (request.getByServiceType() != null
                  ? Filters.componentType(
                      ComponentIds.lookup(request.getByServiceType().toLowerCase()))
                  : Predicates.alwaysTrue());
      final Predicate<ServiceConfiguration> configPredicate = Predicates.and(filters);

      final Collection<ServiceConfiguration> replyConfigs = Lists.newArrayList();
      for (final Component comp : Iterables.filter(Components.list(), componentFilter)) {
        replyConfigs.addAll(Collections2.filter(comp.services(), configPredicate));
      }
      final ImmutableList<ServiceConfiguration> sortedReplyConfigs =
          ServiceOrderings.defaultOrdering().immutableSortedCopy(replyConfigs);
      final Collection<ServiceStatusType> replyStatuses =
          Collections2.transform(
              sortedReplyConfigs, ServiceConfigurations.asServiceStatus(false, false));
      reply.getServiceStatuses().addAll(replyStatuses);
      return reply;
    }
 @Override
 public String getPartition() {
   return ComponentIds.lookup(Eucalyptus.class).name();
 }
 @Override
 public ComponentId getComponentId() {
   return ComponentIds.lookup(CloudFormation.class);
 }
 public ImagingBackendServiceBuilder() {
   super(ComponentIds.lookup(ImagingBackend.class));
 }