Package org.platformlayer.ops

Examples of org.platformlayer.ops.OpsContext


      try {
        // Execute the children in a scope with the paired item and machine
        BindingScope scope = BindingScope.push(machine, target, machineItem);
        try {
          OpsContext opsContext = OpsContext.get();
          OperationRecursor.doRecurseChildren(opsContext, controller);
        } finally {
          scope.pop();
        }
      } catch (OpsException e) {
View Full Code Here


  @Inject
  Injector injector;

  @Override
  public T get() {
    OpsContext opsContext = OpsContext.get();
    if (opsContext == null) {
      throw new IllegalStateException();
    }

    Map<Object, Object> cacheMap = opsContext.getCacheMap();
    T item = (T) cacheMap.get(clazz);
    if (item == null) {
      item = injector.getInstance(clazz);
      cacheMap.put(clazz, item);
    }
View Full Code Here

  public void doOperation() throws OpsException, IOException {
  }

  @Handler(BackupAction.class)
  public void doBackup() throws OpsException, IOException {
    OpsContext opsContext = OpsContext.get();

    // Machine machine = opsContext.getInstance(Machine.class);
    OpsTarget target = opsContext.getInstance(OpsTarget.class);

    // We use pg_dump, not pg_dumpall:
    // 1) pg_dumpall doesn't support binary dumping (?)
    // 2) pg_dumpall wouldn't let us split the dump into different files (?)
View Full Code Here

    Machine machine = new OpaqueMachine(address);
    OpsTarget target = machine.getTarget(sshKey);

    BindingScope scope = BindingScope.push(machine, target);
    try {
      OpsContext opsContext = OpsContext.get();
      OperationRecursor.doRecurseChildren(opsContext, this);
    } finally {
      scope.pop();
    }
  }
View Full Code Here

    logbackLogger.addAppender(appender);
  }

  @Override
  protected void append(E e) {
    OpsContext opsContext = OpsContext.get();

    if (opsContext != null) {
      ILoggingEvent event = (ILoggingEvent) e;

      // Note that we can get the unformatted message in getMessage(), presumably along with the parameters...
      String message = event.getFormattedMessage();
      Level level = event.getLevel();
      int levelInt = level.toInt();

      List<String[]> exceptionStacks = null;

      IThrowableProxy throwableInformation = event.getThrowableProxy();
      while (throwableInformation != null) {
        String[] exceptionStackTrace = null;
        StackTraceElementProxy[] trace = throwableInformation.getStackTraceElementProxyArray();

        String exceptionMessage = throwableInformation.getMessage();
        String exceptionClass = throwableInformation.getClassName();

        if (trace != null) {
          exceptionStackTrace = new String[1 + trace.length];
          exceptionStackTrace[0] = exceptionClass + ": " + exceptionMessage;

          for (int i = 0; i < trace.length; i++) {
            exceptionStackTrace[1 + i] = trace[i].getSTEAsString();
          }
        } else {
          exceptionStackTrace = new String[1];
          exceptionStackTrace[0] = exceptionClass + ": " + exceptionMessage;
        }

        if (exceptionStacks == null) {
          exceptionStacks = Lists.newArrayList();
        }
        exceptionStacks.add(exceptionStackTrace);

        throwableInformation = throwableInformation.getCause();
      }

      if (message != null || exceptionStacks != null) {
        opsContext.getJobLogger().logMessage(message, exceptionStacks, levelInt);

        if (levelInt >= Level.ERROR_INT) {
          // String key = "warn-" + OpsSystem.buildSimpleTimeString() + "-" + (System.nanoTime() % 1000);
          if (opsContext != null) { // && opsContext.getOperation() != null) {
            if (exceptionStacks != null && !exceptionStacks.isEmpty()) {
              String[] exceptionStack = exceptionStacks.get(0);
              if (exceptionStack != null && exceptionStack.length > 0) {
                message += "; " + exceptionStack[0];
              }
            }

            opsContext.addWarning(null, message);
          }
        }
      }
    }
  }
View Full Code Here

    try {
      OpsContextBuilder opsContextBuilder = opsSystem.getInjector().getInstance(OpsContextBuilder.class);

      final ProjectAuthorization project = activeJob.getProjectAuthorization();

      final OpsContext opsContext = opsContextBuilder.buildOpsContext(activeJob);

      final ServiceType serviceType = activeJob.getServiceType();
      final ServiceProvider serviceProvider = opsSystem.getServiceProvider(serviceType);

      try {
        return OpsContext.runInContext(opsContext, new CheckedCallable<Object, Exception>() {
          @Override
          public Object call() throws Exception {
            log.info("Starting job");
            activeJob.setState(JobState.RUNNING);

            ItemBase item;
            ManagedItemRepository repository = opsSystem.getManagedItemRepository();
            try {
              boolean fetchTags = true;
              item = repository.getManagedItem(targetItemKey, fetchTags, SecretProvider.from(project));
            } catch (RepositoryException e) {
              throw new OpsException("Error reading item from repository", e);
            }

            if (item == null) {
              throw new WebApplicationException(404);
            }

            List<Object> scopeItems = Lists.newArrayList();

            addActionScopeItems(action, item, scopeItems);

            Object controller = serviceProvider.getController(item);

            scopeItems.add(item);
            scopeItems.add(action);

            BindingScope scope = BindingScope.push(scopeItems);
            opsContext.recurseOperation(scope, controller);

            // TODO: Should we run a verify operation before -> ACTIVE??
            // (we need to fix the states as well)

            ManagedItemState newState = finishAction(action, scope);
View Full Code Here

    String address = machine.getNetworkPoint().getBestAddress(NetworkPoint.forTargetInContext());
    MysqlTarget mysql = new MysqlTarget(address, username, password);

    BindingScope scope = BindingScope.push(mysql);
    try {
      OpsContext opsContext = OpsContext.get();
      OperationRecursor.doRecurseChildren(opsContext, this);
    } finally {
      scope.pop();
    }
  }
View Full Code Here

    }

    // OpsConfig opsConfig = OpsConfig.build(serviceAuthorization);
    // UserInfo userInfo = new SimpleUserInfo(auth, opsConfig);

    OpsContext opsContext = new OpsContext(opsSystem, activeJob, serviceConfiguration, platformLayerClient,
        projects);
    return opsContext;
  }
View Full Code Here

    for (Machine machine : instanceHelpers.getMachines(dest, required)) {
      OpsTarget target = instanceHelpers.getTarget(dest, machine);

      BindingScope scope = BindingScope.push(machine, target);
      try {
        OpsContext opsContext = OpsContext.get();
        OperationRecursor.doRecurseChildren(opsContext, this);
      } finally {
        scope.pop();
      }
    }
View Full Code Here

  @Inject
  BackupHelpers backups;

  @Handler(BackupAction.class)
  public void doBackup() throws OpsException, IOException {
    OpsContext opsContext = OpsContext.get();

    // Machine machine = opsContext.getInstance(Machine.class);
    OpsTarget target = opsContext.getInstance(OpsTarget.class);

    BackupContext backup = backups.getContext();

    DirectoryBackup request = new DirectoryBackup();
    request.target = target;
View Full Code Here

TOP

Related Classes of org.platformlayer.ops.OpsContext

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.