static boolean shouldInitialize() { // GRZE:WARNING:HACKHACKHACK do not duplicate pls thanks.
   for (final Host h : Hosts.listActiveDatabases()) {
     final String url =
         String.format(
             "jdbc:%s",
             ServiceUris.remote(Database.class, h.getBindAddress(), "eucalyptus_config"));
     try {
       final Connection conn =
           DriverManager.getConnection(url, Databases.getUserName(), Databases.getPassword());
       try {
         final PreparedStatement statement =
             conn.prepareStatement(
                 "select config_component_hostname from config_component_base where config_component_partition='eucalyptus';");
         final ResultSet result = statement.executeQuery();
         while (result.next()) {
           final Object columnValue = result.getObject(1);
           if (Internets.testLocal(columnValue.toString())) {
             return true;
           }
         }
       } finally {
         conn.close();
       }
     } catch (final Exception ex) {
       LOG.error(ex, ex);
     }
   }
   return false;
 }
Beispiel #2
0
 static void sendRedirect(
     final ChannelHandlerContext ctx,
     final ChannelEvent e,
     final Class<? extends ComponentId> compClass,
     final MappingHttpRequest request) {
   e.getFuture().cancel();
   String redirectUri = null;
   if (Topology.isEnabled(compClass)) { // have an enabled service, lets use that
     final URI serviceUri = ServiceUris.remote(Topology.lookup(compClass));
     redirectUri =
         serviceUri.toASCIIString() + request.getServicePath().replace(serviceUri.getPath(), "");
   } else if (Topology.isEnabled(
       Eucalyptus.class)) { // can't find service info, redirect via clc master
     final URI serviceUri = ServiceUris.remote(Topology.lookup(Eucalyptus.class));
     redirectUri =
         serviceUri.toASCIIString().replace(Eucalyptus.INSTANCE.getServicePath(), "")
             + request.getServicePath().replace(serviceUri.getPath(), "");
   }
   HttpResponse response = null;
   if (redirectUri == null || isRedirectLoop(request, redirectUri)) {
     response =
         new DefaultHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.SERVICE_UNAVAILABLE);
     if (Logs.isDebug()) {
       String errorMessage =
           "Failed to lookup service for "
               + Components.lookup(compClass).getName()
               + " for path "
               + request.getServicePath()
               + ".\nCurrent state: \n\t"
               + Joiner.on("\n\t").join(Topology.enabledServices());
       byte[] errorBytes = Exceptions.string(new ServiceStateException(errorMessage)).getBytes();
       response.setContent(ChannelBuffers.wrappedBuffer(errorBytes));
     }
   } else {
     response =
         new DefaultHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.TEMPORARY_REDIRECT);
     if (request.getQuery() != null) {
       redirectUri += "?" + request.getQuery();
     }
     response.setHeader(HttpHeaders.Names.LOCATION, redirectUri);
   }
   response.setHeader(HttpHeaders.Names.CONNECTION, HttpHeaders.Values.CLOSE);
   if (ctx.getChannel().isConnected()) {
     ctx.getChannel().write(response).addListener(ChannelFutureListener.CLOSE);
   }
 }
 /** Utility method for refreshing OSG URI in the S3Client object used by this class. */
 private void refreshOsgURI() {
   try {
     ServiceConfiguration osgConfig = getOsgConfig();
     String osgURI = ServiceUris.remote(osgConfig).toASCIIString();
     s3Client.setS3Endpoint(osgURI);
     LOG.info("Setting objectstorage URI to: " + osgURI);
   } catch (Exception e) {
     LOG.warn("Could not refresh objectstorage URI");
   }
 }
 public static void updateWalrusUrl() {
   try {
     ServiceConfiguration walrusConfig = Topology.lookup(ObjectStorage.class);
     WALRUS_URL = ServiceUris.remote(walrusConfig).toASCIIString();
     StorageProperties.enableSnapshots = true;
     LOG.info("Setting WALRUS_URL to: " + WALRUS_URL);
   } catch (Exception e) {
     LOG.warn(
         "Could not obtain walrus information. Snapshot functionality may be unavailable. Have you registered ObjectStorage?");
     StorageProperties.enableSnapshots = false;
   }
 }
 private static void prepareConnections(final Host host, final String contextName)
     throws NoSuchElementException {
   final String dbUrl =
       "jdbc:" + ServiceUris.remote(Database.class, host.getBindAddress(), contextName);
   final String hostName = host.getDisplayName();
   final DriverDatabaseMBean database = Databases.lookupDatabase(contextName, hostName);
   database.setuser(getUserName());
   database.setpassword(getPassword());
   database.setweight(
       Hosts.isCoordinator(host) ? DATABASE_WEIGHT_PRIMARY : DATABASE_WEIGHT_SECONDARY);
   database.setlocal(host.isLocalHost());
   database.setlocation(dbUrl);
 }