Beispiel #1
0
  @Override
  protected void startNodeRegistration(Injector injector) {
    // Register this node.
    final NodeService nodeService = injector.getInstance(NodeService.class);
    final ServerStatus serverStatus = injector.getInstance(ServerStatus.class);
    final ActivityWriter activityWriter = injector.getInstance(ActivityWriter.class);
    nodeService.registerServer(
        serverStatus.getNodeId().toString(),
        configuration.isMaster(),
        configuration.getRestTransportUri());
    serverStatus.setLocalMode(isLocal());
    if (configuration.isMaster() && !nodeService.isOnlyMaster(serverStatus.getNodeId())) {
      LOG.warn(
          "Detected another master in the cluster. Retrying in {} seconds to make sure it is not "
              + "an old stale instance.",
          TimeUnit.MILLISECONDS.toSeconds(configuration.getStaleMasterTimeout()));
      try {
        Thread.sleep(configuration.getStaleMasterTimeout());
      } catch (InterruptedException e) {
        /* nope */
      }

      if (!nodeService.isOnlyMaster(serverStatus.getNodeId())) {
        // All devils here.
        String what =
            "Detected other master node in the cluster! Starting as non-master! "
                + "This is a mis-configuration you should fix.";
        LOG.warn(what);
        activityWriter.write(new Activity(what, Server.class));

        // Write a notification.
        final NotificationService notificationService =
            injector.getInstance(NotificationService.class);
        Notification notification =
            notificationService
                .buildNow()
                .addType(Notification.Type.MULTI_MASTER)
                .addSeverity(Notification.Severity.URGENT);
        notificationService.publishIfFirst(notification);

        configuration.setIsMaster(false);
      } else {
        LOG.warn("Stale master has gone. Starting as master.");
      }
    }
  }
 @DELETE
 @Path("/{inputId}")
 @Timed
 @ApiOperation(value = "Stop specified input in all nodes")
 @ApiResponses(
     value = {
       @ApiResponse(code = 404, message = "No such input."),
     })
 public Map<String, Optional<InputDeleted>> stop(
     @ApiParam(name = "inputId", required = true) @PathParam("inputId") String inputId) {
   final Map<String, Node> nodes = nodeService.allActive();
   return nodes
       .entrySet()
       .stream()
       .parallel()
       .collect(
           Collectors.toMap(
               Map.Entry::getKey,
               entry -> {
                 final RemoteInputStatesResource remoteInputStatesResource =
                     remoteInterfaceProvider.get(
                         entry.getValue(),
                         this.authenticationToken,
                         RemoteInputStatesResource.class);
                 try {
                   final Response<InputDeleted> response =
                       remoteInputStatesResource.stop(inputId).execute();
                   if (response.isSuccess()) {
                     return Optional.of(response.body());
                   } else {
                     LOG.warn(
                         "Unable to stop input on node {}: {}",
                         entry.getKey(),
                         response.message());
                   }
                 } catch (IOException e) {
                   LOG.warn("Unable to stop input on node {}:", entry.getKey(), e);
                 }
                 return Optional.absent();
               }));
 }
 @GET
 @Timed
 @ApiOperation(value = "Get all input states")
 @RequiresPermissions(RestPermissions.INPUTS_READ)
 public Map<String, Set<InputStateSummary>> get() {
   final Map<String, Node> nodes = nodeService.allActive();
   return nodes
       .entrySet()
       .stream()
       .parallel()
       .collect(
           Collectors.toMap(
               Map.Entry::getKey,
               entry -> {
                 final RemoteInputStatesResource remoteInputStatesResource =
                     remoteInterfaceProvider.get(
                         entry.getValue(),
                         this.authenticationToken,
                         RemoteInputStatesResource.class);
                 try {
                   final Response<InputStatesList> response =
                       remoteInputStatesResource.list().execute();
                   if (response.isSuccess()) {
                     return response.body().states();
                   } else {
                     LOG.warn(
                         "Unable to fetch input states from node {}: {}",
                         entry.getKey(),
                         response.message());
                   }
                 } catch (IOException e) {
                   LOG.warn("Unable to fetch input states from node {}:", entry.getKey(), e);
                 }
                 return Collections.emptySet();
               }));
 }