@Override
    public boolean apply(ModifyServiceType request) {
      try {
        final Topology.Transitions transition =
            Topology.Transitions.valueOf(request.getState().toUpperCase());
        String name = request.getName();
        ServiceConfiguration config = findService(name);
        if (Topology.Transitions.RESTART.equals(transition)) {
          Topology.stop(config).get();
          try {
            Topology.start(config).get();
          } catch (Exception ex) {
            Exceptions.maybeInterrupted(ex);
            Logs.extreme().error(ex, ex);
            throw Exceptions.toUndeclared(ex);
          }
        } else {
          Topology.transition(transition.get()).apply(config).get();
        }
      } catch (final IllegalArgumentException ex) {
        return false;
      } catch (final Exception ex) {
        Exceptions.maybeInterrupted(ex);
        Logs.extreme().error(ex, ex);
        throw Exceptions.toUndeclared(ex);
      }

      return true;
    }
Пример #2
0
 static void update() {
   final Multimap<String, String> partitionVolumeMap = HashMultimap.create();
   final EntityTransaction db = Entities.get(Volume.class);
   try {
     for (final Volume v : Entities.query(Volume.named(null, null))) {
       partitionVolumeMap.put(v.getPartition(), v.getDisplayName());
     }
     db.rollback();
   } catch (final Exception ex) {
     Logs.extreme().error(ex, ex);
     db.rollback();
   }
   Logs.extreme()
       .debug("Volume state update: " + Joiner.on("\n").join(partitionVolumeMap.entries()));
   for (final String partition : partitionVolumeMap.keySet()) {
     try {
       final Map<String, StorageVolume> idStorageVolumeMap =
           updateVolumesInPartition(partition); // TODO:GRZE: restoring volume state
       for (final String v : partitionVolumeMap.get(partition)) {
         try {
           final StorageVolume storageVolume = idStorageVolumeMap.get(v);
           volumeStateUpdate(v, storageVolume);
         } catch (final Exception ex) {
           LOG.error(ex);
           Logs.extreme().error(ex, ex);
         }
       }
     } catch (final Exception ex) {
       LOG.error(ex);
       Logs.extreme().error(ex, ex);
     }
   }
 }
 private static VmInstance maybeFindVm(
     final String instanceId, final String publicIp, final String privateIp) {
   VmInstance vm = null;
   if (instanceId != null) {
     try {
       vm = VmInstances.lookup(instanceId);
     } catch (NoSuchElementException ex) {
       Logs.extreme().error(ex);
     }
   }
   if (vm == null && privateIp != null) {
     try {
       vm = VmInstances.lookupByPrivateIp(privateIp);
     } catch (NoSuchElementException ex) {
       Logs.extreme().error(ex);
     }
   }
   if (vm == null && publicIp != null) {
     try {
       vm = VmInstances.lookupByPublicIp(publicIp);
     } catch (NoSuchElementException ex) {
       Logs.extreme().error(ex);
     }
   }
   if (vm != null
       && VmState.RUNNING.equals(vm.getState())
       && publicIp.equals(vm.getPublicAddress())) {
     Logs.extreme()
         .debug(
             "Candidate vm which claims this address: "
                 + vm.getInstanceId()
                 + " "
                 + vm.getState()
                 + " "
                 + publicIp);
     if (publicIp.equals(vm.getPublicAddress())) {
       Logs.extreme()
           .debug(
               "Found vm which claims this address: "
                   + vm.getInstanceId()
                   + " "
                   + vm.getState()
                   + " "
                   + publicIp);
     }
     return vm;
   } else {
     return null;
   }
 }
Пример #4
0
 @Override
 public Set<String> get() {
   Set<String> hosts = DBHOSTS.get();
   Set<String> union = Sets.newHashSet();
   Set<String> intersection = Sets.newHashSet(hosts);
   Logs.extreme().debug("ActiveHostSet: universe of db hosts: " + hosts);
   for (String ctx : PersistenceContexts.list()) {
     try {
       Set<String> activeDatabases = Databases.lookup(ctx, 0).getactiveDatabases();
       if (BootstrapArgs.isCloudController()) {
         activeDatabases.add(
             Internets
                 .localHostIdentifier()); // GRZE: use Internets.localHostIdentifier() which is
                                          // static, rather than the Hosts reference as it is
                                          // stateful
       }
       union.addAll(activeDatabases);
       intersection.retainAll(activeDatabases);
     } catch (Exception ex) {
     }
   }
   Logs.extreme().debug("ActiveHostSet: union of activated db connections: " + union);
   Logs.extreme()
       .debug(
           "ActiveHostSet: intersection of db hosts and activated db connections: "
               + intersection);
   boolean dbVolatile = !hosts.equals(intersection);
   String msg =
       String.format(
           "ActiveHostSet: %-14.14s %s%s%s",
           dbVolatile ? "volatile" : "synchronized",
           hosts,
           dbVolatile ? "!=" : "=",
           intersection);
   if (dbVolatile) {
     if (last.compareAndSet(false, dbVolatile)) {
       LOG.warn(msg);
     } else {
       LOG.debug(msg);
     }
   } else {
     if (last.compareAndSet(true, dbVolatile)) {
       LOG.warn(msg);
     } else {
       Logs.extreme().info(msg);
     }
   }
   return intersection;
 }
Пример #5
0
 /**
  * @delegate Do not change semantics here.
  * @see javax.persistence.EntityTransaction#rollback()
  */
 @Override
 public void rollback() throws RecoverablePersistenceException {
   removeTransaction(this);
   if ((this.txState != null) && this.txState.isActive()) {
     try {
       this.txState.rollback();
       this.txState = null;
     } catch (final RuntimeException ex) {
       Logs.extreme().error(ex);
       //          throw PersistenceExceptions.throwFiltered( ex );
     }
   } else {
     Logs.extreme().debug("Duplicate call to rollback( )");
   }
 }
Пример #6
0
 public TypeBinding getTypeBinding(Field field) {
   Class itsType = field.getType();
   if (this.isIgnored(field)) {
     return new NoopTypeBinding(field);
   } else if (List.class.isAssignableFrom(itsType)) {
     Class listType = getTypeArgument(field);
     if (listType == null) {
       Logs.extreme()
           .debug(
               String.format(
                   "IGNORE: %-70s [type=%s] NO GENERIC TYPE FOR LIST\n",
                   field.getDeclaringClass().getCanonicalName() + "." + field.getName(),
                   listType));
       return new NoopTypeBinding(field);
     } else if (this.typeBindings.containsKey(listType.getCanonicalName())) {
       return new CollectionTypeBinding(
           field.getName(), this.typeBindings.get(listType.getCanonicalName()));
     } else if (BindingFileSearch.INSTANCE.MSG_DATA_CLASS.isAssignableFrom(listType)) {
       return new CollectionTypeBinding(
           field.getName(), new ObjectTypeBinding(field.getName(), listType));
     } else {
       Logs.extreme()
           .debug(
               String.format(
                   "IGNORE: %-70s [type=%s] LIST'S GENERIC TYPE DOES NOT CONFORM TO EucalyptusData\n",
                   field.getDeclaringClass().getCanonicalName() + "." + field.getName(),
                   listType.getCanonicalName()));
       return new NoopTypeBinding(field);
     }
   } else if (this.typeBindings.containsKey(itsType.getCanonicalName())) {
     TypeBinding t = this.typeBindings.get(itsType.getCanonicalName());
     try {
       t = this.typeBindings.get(itsType.getCanonicalName()).getClass().newInstance();
     } catch (Exception e) {
     }
     return t.value(field.getName());
   } else if (BindingFileSearch.INSTANCE.MSG_DATA_CLASS.isAssignableFrom(field.getType())) {
     return new ObjectTypeBinding(field);
   } else {
     Logs.extreme()
         .debug(
             String.format(
                 "IGNORE: %-70s [type=%s] TYPE DOES NOT CONFORM TO EucalyptusData\n",
                 field.getDeclaringClass().getCanonicalName() + "." + field.getName(),
                 field.getType().getCanonicalName()));
     return new NoopTypeBinding(field);
   }
 }
Пример #7
0
 public void processClass(Class klass) {
   if (this.out == null) {
     if (this.outFile.exists()) {
       this.outFile.delete();
     }
     try {
       this.out = new PrintWriter(this.outFile);
     } catch (FileNotFoundException e) {
       e.printStackTrace(System.err);
       System.exit(-1); // GRZE: special case to fail build
     }
     this.bindingName = this.ns.replaceAll("(http://)|(/$)", "").replaceAll("[./-]", "_");
     this.out.write(
         "<binding xmlns:euca=\"" + this.ns + "\" name=\"" + this.bindingName + "\">\n");
     this.out.write(
         "  <namespace uri=\"" + this.ns + "\" default=\"elements\" prefix=\"euca\"/>\n");
     this.out.flush();
   }
   if (!classNames.contains(klass.getName())) {
     classNames.add(klass.getName());
     String mapping = new RootObjectTypeBinding(klass).process();
     this.out.write(mapping);
     this.out.flush();
   } else {
     Logs.extreme().debug("Skipping duplicate class: " + klass);
   }
 }
Пример #8
0
 private boolean transition(
     State expectedState,
     State newState,
     boolean expectedMark,
     boolean newMark,
     SplitTransition transition) {
   this.transition = transition;
   if (!this.atomicState.compareAndSet(expectedState, newState, expectedMark, newMark)) {
     throw new IllegalStateException(
         String.format(
             "Cannot mark address as %s[%s.%s->%s.%s] when it is %s.%s: %s",
             transition.getName(),
             expectedState,
             expectedMark,
             newState,
             newMark,
             this.atomicState.getReference(),
             this.atomicState.isMarked(),
             this.toString()));
   }
   EventRecord.caller(this.getClass(), EventType.ADDRESS_STATE, "TOP", this.toString()).info();
   try {
     this.transition.top();
   } catch (RuntimeException ex) {
     LOG.error(ex);
     Logs.extreme().error(ex, ex);
     throw ex;
   }
   return true;
 }
Пример #9
0
 @Override
 public R apply(final D input) {
   RuntimeException rootCause = null;
   for (int i = 0; i < retries; i++) {
     EntityTransaction db = Entities.get(this.entityType);
     try {
       R ret = this.function.apply(input);
       db.commit();
       return ret;
     } catch (RuntimeException ex) {
       db.rollback();
       if (Exceptions.isCausedBy(ex, OptimisticLockException.class)) {
         rootCause = Exceptions.findCause(ex, OptimisticLockException.class);
       } else if (Exceptions.isCausedBy(ex, LockAcquisitionException.class)) {
         rootCause = Exceptions.findCause(ex, LockAcquisitionException.class);
       } else {
         rootCause = ex;
         Logs.extreme().error(ex, ex);
         throw ex;
       }
       try {
         TimeUnit.MILLISECONDS.sleep(20);
       } catch (InterruptedException ex1) {
         Exceptions.maybeInterrupted(ex1);
       }
       continue;
     }
   }
   throw (rootCause != null
       ? rootCause
       : new NullPointerException(
           "BUG: Transaction retry failed but root cause exception is unknown!"));
 }
  @Override
  public void messageReceived(ChannelHandlerContext ctx, MessageEvent event) throws Exception {
    if (event.getMessage() instanceof MappingHttpRequest) {
      MappingHttpRequest httpRequest = (MappingHttpRequest) event.getMessage();

      if (httpRequest.getMessage() instanceof ObjectStorageDataRequestType) {
        if (httpRequest.isChunked()) {
          // Chunked request, and beginning, setup map etc.
          initializeNewPut(ctx, (ObjectStorageDataRequestType) httpRequest.getMessage());
        }
      }
    } else if (event.getMessage() instanceof HttpChunk) {
      // Add the chunk to the current streams channel buffer.
      HttpChunk chunk = (HttpChunk) event.getMessage();
      appendChunk(chunk.getContent(), ctx.getChannel());

      if (chunk.isLast()) {
        // Remove from the map
        Logs.extreme()
            .debug(
                "Removing data map due to last chunk processed event for channel: "
                    + ctx.getChannel().getId());
        dataMap.remove(ctx.getChannel());
      }
    }
    // Always pass it on
    ctx.sendUpstream(event);
  }
Пример #11
0
 @Override
 public void handleUpstream(final ChannelHandlerContext ctx, final ChannelEvent e)
     throws Exception {
   final MappingHttpRequest request = MappingHttpMessage.extractMessage(e);
   final BaseMessage msg = BaseMessage.extractMessage(e);
   if (msg != null) {
     try {
       final Class<? extends ComponentId> compClass = ComponentMessages.lookup(msg);
       ComponentId compId = ComponentIds.lookup(compClass);
       if (compId.isAlwaysLocal() || Topology.isEnabledLocally(compClass)) {
         ctx.sendUpstream(e);
       } else {
         Handlers.sendRedirect(ctx, e, compClass, request);
       }
     } catch (final NoSuchElementException ex) {
       LOG.warn(
           "Failed to find reverse component mapping for message type: " + msg.getClass());
       ctx.sendUpstream(e);
     } catch (final Exception ex) {
       Logs.extreme().error(ex, ex);
       ctx.sendUpstream(e);
     }
   } else {
     ctx.sendUpstream(e);
   }
 }
 @Override
 public void fireException(Throwable e) {
   LOG.debug(e);
   Logs.extreme().error(e, e);
   LOG.debug(
       "Trying to remove invalid volume attachment "
           + this.getRequest().getVolumeId()
           + " from instance "
           + this.getRequest().getInstanceId());
   try {
     VmInstance vm = VmInstances.lookup(this.getRequest().getInstanceId());
     Partition partition = vm.lookupPartition();
     ServiceConfiguration sc = Topology.lookup(Storage.class, partition);
     /** clean up SC session state * */
     try {
       LOG.debug(
           "Sending detach after async failure in attach volume: "
               + this.getRequest().getVolumeId()
               + " sc="
               + sc);
       AsyncRequests.sendSync(sc, new DetachStorageVolumeType(this.getRequest().getVolumeId()));
     } catch (Exception ex) {
       LOG.error(ex);
       Logs.extreme().error(ex, ex);
     }
     /** clean up internal attachment state * */
     final Function<String, VmInstance> removeVolAttachment =
         new Function<String, VmInstance>() {
           public VmInstance apply(final String input) {
             VmInstance vm = VmInstances.lookup(input);
             vm.removeVolumeAttachment(VolumeAttachCallback.this.getRequest().getVolumeId());
             return vm;
           }
         };
     Entities.asTransaction(VmInstance.class, removeVolAttachment)
         .apply(this.getRequest().getInstanceId());
     LOG.debug(
         "Removed failed attachment: "
             + this.getRequest().getVolumeId()
             + " -> "
             + vm.getInstanceId());
   } catch (Exception e1) {
     LOG.error(e1);
     Logs.extreme().error(e1, e1);
   }
 }
Пример #13
0
 @Override
 public String toString() {
   Logs.extreme()
       .debug("Found list type: " + this.type.getTypeName() + " for name: " + this.name);
   String ret = this.type.collection(this.name).buf.toString();
   this.type.collection(this.name).buf = new StringBuilder();
   return ret;
 }
 protected void initializeNewPut(ChannelHandlerContext ctx, ObjectStorageDataRequestType request)
     throws IllegalStateException {
   Logs.extreme()
       .debug(
           "Adding entry to data map in PUT aggregator for channel: " + ctx.getChannel().getId());
   ChannelBufferStreamingInputStream stream = request.getData();
   ChannelBufferStreamingInputStream foundStream = dataMap.putIfAbsent(ctx.getChannel(), stream);
   if (foundStream != null) {
     Logs.extreme()
         .debug(
             "Found existing entry in map for this channel. Streams should never cross. Throwing illegal state for channel: "
                 + ctx.getChannel().getId());
     throw new IllegalStateException(
         "Duplicate messages for same PUT, cannot overwrite data buffer. Channel:"
             + ctx.getChannel().getId());
   }
 }
Пример #15
0
 /**
  * @delegate Do not change semantics here.
  * @see javax.persistence.EntityTransaction#commit()
  */
 @Override
 public void commit() {
   try {
     this.transaction.commit();
   } catch (final RuntimeException ex) {
     LOG.trace(ex, ex);
     Logs.extreme().warn(ex, ex);
     throw ex;
   }
 }
Пример #16
0
 private static void rollback(final Host host, Exception ex) {
   try {
     Databases.runDbStateChange(
         Databases.DeactivateHostFunction.INSTANCE.apply(host.getDisplayName()));
   } catch (LockTimeoutException ex1) {
     Databases.LOG.error("Databases.enable(): failed because of: " + ex.getMessage());
   } catch (Exception ex1) {
     Databases.LOG.error("Databases.enable(): failed because of: " + ex.getMessage());
     Logs.extreme().error(ex, ex);
   }
 }
Пример #17
0
    public void process(File f) throws Exception {
      if (f.isDirectory()) {
        File[] files =
            f.listFiles(
                new FilenameFilter() {

                  @Override
                  public boolean accept(File dir, String name) {
                    return name.matches(FILE_PATTERN);
                  }
                });
        for (File ff : files) {
          byte[] bindingBytes = Files.toByteArray(ff);
          this.addCurrentBinding(bindingBytes, ff.getName(), "file:" + ff.getAbsolutePath());
        }
      } else {
        String digest = new BigInteger(Files.getDigest(f, Digest.MD5.get())).abs().toString(16);
        CURRENT_PROPS.put(BINDING_CACHE_JAR_PREFIX + f.getName(), digest);
        final JarFile jar = new JarFile(f);
        final List<JarEntry> jarList = Collections.list(jar.entries());
        for (final JarEntry j : jarList) {
          try {
            if (j.getName().matches(FILE_PATTERN)) {
              byte[] bindingBytes = ByteStreams.toByteArray(jar.getInputStream(j));
              String bindingName = j.getName();
              String bindingFullPath = "jar:file:" + f.getAbsolutePath() + "!/" + bindingName;
              this.addCurrentBinding(bindingBytes, bindingName, bindingFullPath);
            } else if (j.getName().matches(".*\\.class.{0,1}")) {
              final String classGuess =
                  j.getName().replaceAll("/", ".").replaceAll("\\.class.{0,1}", "");
              final Class candidate = ClassLoader.getSystemClassLoader().loadClass(classGuess);
              if (MSG_BASE_CLASS.isAssignableFrom(candidate)
                  || MSG_DATA_CLASS.isAssignableFrom(candidate)) {
                InputSupplier<InputStream> classSupplier =
                    Resources.newInputStreamSupplier(ClassLoader.getSystemResource(j.getName()));
                File destClassFile = SubDirectory.CLASSCACHE.getChildFile(j.getName());
                if (!destClassFile.exists()) {
                  Files.createParentDirs(destClassFile);
                  Files.copy(classSupplier, destClassFile);
                  Logs.extreme()
                      .debug("Caching: " + j.getName() + " => " + destClassFile.getAbsolutePath());
                }
                BINDING_CLASS_MAP.putIfAbsent(classGuess, candidate);
              }
            }
          } catch (RuntimeException ex) {
            LOG.error(ex, ex);
            jar.close();
            throw ex;
          }
        }
        jar.close();
      }
    }
Пример #18
0
 /**
  * @delegate Do not change semantics here.
  * @see javax.persistence.EntityTransaction#commit()
  */
 @Override
 public void commit() throws RecoverablePersistenceException {
   removeTransaction(this);
   if ((this.txState != null) && this.txState.isActive()) {
     try {
       this.txState.commit();
     } catch (final RuntimeException ex) {
       throw PersistenceExceptions.throwFiltered(ex);
     }
   } else {
     Logs.extreme().error("Duplicate call to commit( ): " + Threads.currentStackString());
   }
 }
Пример #19
0
 /**
  * Private for a reason.
  *
  * @see {@link CascadingTx#get(Class)}
  * @param persistenceContext
  * @throws RecoverablePersistenceException
  */
 @SuppressWarnings("unchecked")
 CascadingTx(final String ctx) throws RecoverablePersistenceException {
   final StackTraceElement ste = Threads.currentStackFrame(4);
   final String uuid = UUID.randomUUID().toString();
   this.record = new TxRecord(ctx, uuid, ste);
   try {
     this.txState = new TxState(ctx);
   } catch (final RuntimeException ex) {
     Logs.extreme().error(ex, ex);
     this.rollback();
     throw PersistenceExceptions.throwFiltered(ex);
   }
 }
Пример #20
0
  private static void runDbStateChange(Function<String, Runnable> runnableFunction) {
    Logs.extreme().info("DB STATE CHANGE: " + runnableFunction);
    try {
      Logs.extreme().info("Attempting to acquire db state lock: " + runnableFunction);
      if (canHas.writeLock().tryLock(5, TimeUnit.MINUTES)) {

        try {
          Logs.extreme().info("Acquired db state lock: " + runnableFunction);
          Map<Runnable, Future<Runnable>> runnables = Maps.newHashMap();
          for (final String ctx : listDatabases()) {
            Runnable run = runnableFunction.apply(ctx);
            runnables.put(run, ExecuteRunnable.INSTANCE.apply(run));
          }
          Map<Runnable, Future<Runnable>> succeeded = Futures.waitAll(runnables);
          MapDifference<Runnable, Future<Runnable>> failed = Maps.difference(runnables, succeeded);
          StringBuilder builder = new StringBuilder();
          builder.append(Joiner.on("\nSUCCESS: ").join(succeeded.keySet()));
          builder.append(Joiner.on("\nFAILED:  ").join(failed.entriesOnlyOnLeft().keySet()));
          Logs.extreme().debug(builder.toString());
          if (!failed.entriesOnlyOnLeft().isEmpty()) {
            throw Exceptions.toUndeclared(builder.toString());
          }
        } finally {
          canHas.writeLock().unlock();
        }
      } else {
        throw new LockTimeoutException(
            "DB STATE CHANGE ABORTED (failed to get lock): " + runnableFunction);
      }
    } catch (RuntimeException ex) {
      LOG.error(ex);
      Logs.extreme().error(ex, ex);
      throw ex;
    } catch (InterruptedException ex) {
      Exceptions.maybeInterrupted(ex);
      throw Exceptions.toUndeclared(ex);
    }
  }
 @Override
 public void channelClosed(ChannelHandlerContext ctx, ChannelStateEvent evt) throws Exception {
   // Clear the map for this context
   try {
     Logs.extreme()
         .debug(
             "Removing data map on channel closed event for channel: " + ctx.getChannel().getId());
     dataMap.remove(ctx.getChannel());
   } catch (final Throwable f) {
     // Nothing to lookup.
   } finally {
     super.channelClosed(ctx, evt);
   }
 }
Пример #22
0
 static boolean disable(final String hostName) {
   if (!Bootstrap.isFinished()) {
     return false;
   } else if (Internets.testLocal(hostName)) {
     return true;
   } else {
     try {
       runDbStateChange(DeactivateHostFunction.INSTANCE.apply(hostName));
       return true;
     } catch (Exception ex) {
       Logs.extreme().debug(ex);
       return false;
     }
   }
 }
Пример #23
0
 public RemoteCallback getCallback() {
   try {
     Class cbClass = this.transition.getName().getCallback();
     Constructor cbCons = cbClass.getConstructor(Address.class);
     return (RemoteCallback) cbCons.newInstance(this);
   } catch (Exception ex) {
     LOG.error(ex);
     Logs.extreme().error(ex, ex);
     try {
       this.clearPending();
     } catch (Exception ex1) {
     }
     return new NOOP();
   }
 }
Пример #24
0
 private static void removeAddress(final String ipAddress) {
   try {
     Addresses.getInstance().disable(ipAddress);
   } catch (NoSuchElementException e1) {
     LOG.debug(e1);
   }
   EntityWrapper<Address> db = EntityWrapper.get(Address.class);
   try {
     Address searchAddr = new Address(ipAddress);
     searchAddr.setOwner(null);
     Address dbAddr = db.getUnique(searchAddr);
     db.delete(dbAddr);
     db.commit();
   } catch (Exception e) {
     Logs.extreme().error(e, e);
     db.rollback();
   }
 }
Пример #25
0
 public Address clearPending() {
   if (!this.atomicState.isMarked()) {
     throw new IllegalStateException("Trying to clear an address which is not currently pending.");
   } else {
     EventRecord.caller(this.getClass(), EventType.ADDRESS_STATE, "BOTTOM", this.toString())
         .info();
     try {
       this.transition.bottom();
     } catch (RuntimeException ex) {
       LOG.error(ex);
       Logs.extreme().error(ex, ex);
     } finally {
       this.transition = this.QUIESCENT;
       this.atomicState.set(this.atomicState.getReference(), false);
     }
   }
   return this;
 }
Пример #26
0
 public static <T> T uniqueResult(final T example)
     throws TransactionException, NoSuchElementException {
   try {
     final Object pk = resolvePrimaryKey(example);
     final String natId = resolveNaturalId(example);
     if (pk != null) {
       return maybePrimaryKey(example);
     } else if (natId != null) {
       return maybeNaturalId(example);
     } else {
       return maybeDefinitelyExample(example);
     }
   } catch (final NoSuchElementException ex) {
     throw ex;
   } catch (final RuntimeException ex) {
     Logs.extreme().trace(ex, ex);
     final Exception newEx = PersistenceExceptions.throwFiltered(ex);
     throw new TransactionInternalException(newEx.getMessage(), newEx);
   }
 }
 protected void appendChunk(ChannelBuffer input, Channel channel) throws Exception {
   Logs.extreme()
       .debug(
           "Writing content data to stream for channel: "
               + channel.getId()
               + " Content length: "
               + input.readableBytes());
   ChannelBufferStreamingInputStream stream = dataMap.get(channel);
   if (stream == null) {
     throw new IllegalStateException(
         "received "
             + HttpChunk.class.getSimpleName()
             + " without "
             + HttpMessage.class.getSimpleName());
   }
   // Write the content into the buffer.
   try {
     stream.putChunk(input);
   } catch (Exception ex) {
     throw new IllegalStateException(ex);
   }
 }
 public static DestroyServiceResponseType destroyService(final DestroyServiceType request)
     throws Exception {
   DestroyServiceResponseType reply = request.getReply();
   for (final ServiceId serviceInfo : request.getServices()) {
     try {
       final ServiceConfiguration service =
           TypeMappers.transform(serviceInfo, ServiceConfiguration.class);
       if (service.isVmLocal()) {
         try {
           Topology.destroy(service).get();
         } catch (final IllegalStateException ex) {
           LOG.error(ex, ex);
         }
       }
       reply.getServices().add(serviceInfo);
     } catch (final Exception ex) {
       LOG.error(ex);
       Logs.extreme().debug(ex, ex);
     }
   }
   return reply;
 }
Пример #29
0
 @Override
 public void handleUpstream(final ChannelHandlerContext ctx, final ChannelEvent e)
     throws Exception {
   final MappingHttpRequest request = MappingHttpMessage.extractMessage(e);
   final BaseMessage msg = BaseMessage.extractMessage(e);
   if (msg != null) {
     try {
       if (msg instanceof ServiceTransitionType && !Hosts.isCoordinator()) {
         // TODO:GRZE: extra epoch check and redirect
         Topology.touch((ServiceTransitionType) msg);
         ctx.sendUpstream(e);
       } else if (Topology.check(msg)) {
         ctx.sendUpstream(e);
       } else {
         final Class<? extends ComponentId> compClass = ComponentMessages.lookup(msg);
         Handlers.sendRedirect(ctx, e, compClass, request);
       }
     } catch (final Exception ex) {
       Logs.extreme().error(ex, ex);
       ctx.sendUpstream(e);
     }
   }
 }
Пример #30
0
 static Map<String, StorageVolume> updateVolumesInPartition(final String partition) {
   final Map<String, StorageVolume> idStorageVolumeMap = Maps.newHashMap();
   final ServiceConfiguration scConfig =
       Topology.lookup(Storage.class, Partitions.lookupByName(partition));
   try {
     final DescribeStorageVolumesResponseType volState =
         AsyncRequests.sendSync(scConfig, new DescribeStorageVolumesType());
     for (final StorageVolume vol : volState.getVolumeSet()) {
       LOG.trace(
           "Volume states: "
               + vol.getVolumeId()
               + " "
               + vol.getStatus()
               + " "
               + vol.getActualDeviceName());
       idStorageVolumeMap.put(vol.getVolumeId(), vol);
     }
   } catch (final Exception ex) {
     LOG.error(ex);
     Logs.extreme().error(ex, ex);
   }
   return idStorageVolumeMap;
 }