Esempio n. 1
0
 private static ClientIdentifier toClientIdentifier(PlatformConnectedClient connection) {
   return ClientIdentifier.create(
       connection.clientPID,
       connection.remoteAddress.getHostAddress(),
       connection.name == null || connection.name.isEmpty() ? "UNKNOWN" : connection.name,
       connection.uuid);
 }
  @Override
  public String sendManagementCallRequest(
      ClientDescriptor caller,
      final Context context,
      String capabilityName,
      String methodName,
      Class<?> returnType,
      Parameter... parameters) {
    LOGGER.trace(
        "[{}] sendManagementCallRequest({}, {}, {})",
        consumerId,
        context,
        capabilityName,
        methodName);

    String managementCallIdentifier = UUID.randomUUID().toString();
    Context fullContext = null;

    if (context.contains(Client.KEY)) {
      // handle client call
      ClientIdentifier to = ClientIdentifier.valueOf(context.get(Client.KEY));
      fullContext =
          context.with(
              topologyService
                  .getManageableClientContext(to)
                  .orElseThrow(
                      () ->
                          new IllegalStateException(
                              "Client " + to + " is either not found or not manageable")));
    }

    if ((context.contains(Server.NAME_KEY) || context.contains(Server.KEY))
        && (context.contains(ServerEntity.CONSUMER_ID)
            || context.contains(ServerEntity.TYPE_KEY)
                && context.contains(ServerEntity.NAME_KEY))) {
      // handle entity call
      String serverName = context.getOrDefault(Server.NAME_KEY, context.get(Server.KEY));
      Context entityCtx =
          (context.contains(ServerEntity.CONSUMER_ID)
                  ? topologyService.getManageableEntityContext(
                      serverName, Long.parseLong(context.get(ServerEntity.CONSUMER_ID)))
                  : topologyService.getManageableEntityContext(
                      serverName,
                      context.get(ServerEntity.NAME_KEY),
                      context.get(ServerEntity.TYPE_KEY)))
              .orElseThrow(
                  () ->
                      new IllegalStateException(
                          "Server Entity " + context + " is either not found or not manageable"));
      fullContext = context.with(entityCtx);
    }

    if (fullContext == null) {
      throw new IllegalArgumentException(context.toString());
    }

    track(caller, managementCallIdentifier);
    eventService.fireManagementCallRequest(
        managementCallIdentifier,
        new ContextualCall<>(fullContext, capabilityName, methodName, returnType, parameters));
    return managementCallIdentifier;
  }
Esempio n. 3
0
 static boolean isManageableClient(IMonitoringConsumer consumer, ClientIdentifier to) {
   return consumer.getChildNamesForNode("management", "clients", to.getClientId()).isPresent();
 }