Пример #1
0
 private void handleInitialize(ChannelHandlerContext ctx, MappingHttpRequest request)
     throws IOException, SocketException {
   InetSocketAddress addr = (InetSocketAddress) ctx.getChannel().getRemoteAddress();
   LOG.info(LogUtil.subheader("Using " + addr.getHostName() + " as the database address."));
   Component.db.setHostAddress(addr.getHostName());
   Component.db.markEnabled();
   Component.dns.setHostAddress(addr.getHostName());
   Component.eucalyptus.setHostAddress(addr.getHostName());
   Component.cluster.setHostAddress(addr.getHostName());
   Component.jetty.setHostAddress(addr.getHostName());
   HeartbeatType msg = (HeartbeatType) request.getMessage();
   LOG.info(LogUtil.header("Got heartbeat event: " + LogUtil.dumpObject(msg)));
   for (HeartbeatComponentType component : msg.getComponents()) {
     LOG.info(LogUtil.subheader("Registering local component: " + LogUtil.dumpObject(component)));
     System.setProperty("euca." + component.getComponent() + ".name", component.getName());
     Component.valueOf(component.getComponent()).markLocal();
     // FIXME: this is needed because we can't dynamically change the mule config, so we need to
     // disable at init time and hup when a new component is loaded.
     initializedComponents.add(component.getComponent());
   }
   // FIXME: this is needed because we can't dynamically change the mule config, so we need to
   // disable at init time and hup when a new component is loaded.
   if (!initializedComponents.contains(Component.storage.name())) {
     Component.storage.markDisabled();
   }
   // FIXME: this is needed because we can't dynamically change the mule config, so we need to
   // disable at init time and hup when a new component is loaded.
   if (!initializedComponents.contains(Component.walrus.name())) {
     Component.walrus.markDisabled();
   }
   System.setProperty("euca.db.password", Hashes.getHexSignature());
   System.setProperty("euca.db.url", Component.db.getUri().toASCIIString());
   boolean foundDb = false;
   try {
     foundDb = NetworkUtil.testReachability(addr.getHostName());
     LOG.debug("Initializing SSL just in case: " + SslSetup.class);
     foundDb = true;
   } catch (Throwable e) {
     foundDb = false;
   }
   if (foundDb) {
     HttpResponse response =
         new DefaultHttpResponse(request.getProtocolVersion(), HttpResponseStatus.OK);
     ChannelFuture writeFuture = ctx.getChannel().write(response);
     writeFuture.addListener(ChannelFutureListener.CLOSE);
     initialized = true;
     if (this.channel != null) {
       this.channel.close();
     }
   } else {
     HttpResponse response =
         new DefaultHttpResponse(request.getProtocolVersion(), HttpResponseStatus.NOT_ACCEPTABLE);
     ChannelFuture writeFuture = ctx.getChannel().write(response);
     writeFuture.addListener(ChannelFutureListener.CLOSE);
   }
 }
Пример #2
0
 @Override
 public void messageReceived(ChannelHandlerContext ctx, MessageEvent e) throws Exception {
   Object message = ((MessageEvent) e).getMessage();
   if (message instanceof MappingHttpRequest) {
     MappingHttpRequest request = ((MappingHttpRequest) message);
     if (HttpMethod.GET.equals(request.getMethod())) {
       handleGet(ctx, request);
     } else if (!initialized) {
       handleInitialize(ctx, request);
     } else if (request.getMessage() instanceof HeartbeatType) {
       handleHeartbeat(request);
     } else {
       ChannelFuture writeFuture =
           ctx.getChannel()
               .write(
                   new DefaultHttpResponse(
                       request.getProtocolVersion(), HttpResponseStatus.NOT_ACCEPTABLE));
       writeFuture.addListener(ChannelFutureListener.CLOSE);
     }
   } else {
     super.messageReceived(ctx, e);
   }
 }
Пример #3
0
 private void handleHeartbeat(MappingHttpRequest request) throws URISyntaxException {
   HeartbeatType hb = (HeartbeatType) request.getMessage();
   // FIXME: this is needed because we can't dynamically change the mule config, so we need to
   // disable at init time and hup when a new component is loaded.
   List<String> registeredComponents = Lists.newArrayList();
   for (HeartbeatComponentType component : hb.getComponents()) {
     if (!initializedComponents.contains(component.getComponent())) {
       System.exit(123); // HUP
     }
     registeredComponents.add(component.getComponent());
   }
   if (!registeredComponents.containsAll(initializedComponents)) {
     System.exit(123); // HUP
   }
   // FIXME: end.
   for (ComponentType startedComponent : hb.getStarted()) {
     Component c = Component.valueOf(startedComponent.getComponent());
     try {
       if (Component.walrus.equals(c)) {
         ComponentConfiguration config =
             Configuration.getWalrusConfiguration(startedComponent.getName());
         Configuration.fireStartComponent(config);
       }
       if (Component.storage.equals(c)) {
         ComponentConfiguration config =
             Configuration.getStorageControllerConfiguration(startedComponent.getName());
         Configuration.fireStartComponent(config);
       }
     } catch (Exception e1) {
       LOG.debug(e1, e1);
     }
   }
   for (ComponentType stoppedComponent : hb.getStopped()) {
     URI uri = new URI(stoppedComponent.getUri());
     Component c = Component.valueOf(stoppedComponent.getComponent());
     try {
       if (Component.walrus.equals(c)) {
         Configuration.fireStopComponent(new RemoteConfiguration(c, uri));
       }
       if (Component.storage.equals(c)) {
         Configuration.fireStopComponent(new RemoteConfiguration(c, uri));
       }
     } catch (Exception e1) {
       LOG.debug(e1, e1);
     }
   }
 }
Пример #4
0
 private void handleGet(ChannelHandlerContext ctx, MappingHttpRequest request) {
   MappingHttpResponse response =
       new MappingHttpResponse(request.getProtocolVersion(), HttpResponseStatus.OK);
   String resp = "";
   for (Component c : Component.values()) {
     resp +=
         String.format(
             "name=%-20.20s enabled=%-10.10s local=%-10.10s initialized=%-10.10s\n",
             c.name(), c.isEnabled(), c.isLocal(), c.isInitialized());
   }
   ChannelBuffer buf = ChannelBuffers.copiedBuffer(resp.getBytes());
   response.setContent(buf);
   response.addHeader(HttpHeaders.Names.CONTENT_LENGTH, String.valueOf(buf.readableBytes()));
   response.addHeader(HttpHeaders.Names.CONTENT_TYPE, "text/plain; charset=UTF-8");
   ChannelFuture writeFuture = ctx.getChannel().write(response);
   writeFuture.addListener(ChannelFutureListener.CLOSE);
 }