Exemplo n.º 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);
   }
 }
Exemplo n.º 2
0
 private synchronized HeartbeatType getMessage(
     Collection<ComponentConfiguration> componentConfigurations) {
   HeartbeatType hbmsg = new HeartbeatType();
   hbmsg.getStarted().addAll(started);
   this.started.clear();
   hbmsg.getStopped().addAll(stopped);
   this.stopped.clear();
   for (ComponentConfiguration c : componentConfigurations) {
     hbmsg.getComponents().add(new HeartbeatComponentType(c.getComponent().name(), c.getName()));
   }
   return hbmsg;
 }
Exemplo n.º 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);
     }
   }
 }