Package org.platformlayer.ops

Examples of org.platformlayer.ops.BindingScope$BindingScopeStack


      OpsTarget target = machine.getTarget(sshKey);

      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) {
        failed = true;
        log.warn("Error updating machine: " + machine, e);
      }
View Full Code Here


  @Override
  public void doRecurseOperation() throws OpsException {
    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

            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);
            if (newState != null) {
              repository.changeState(targetItemKey, newState);
              item.state = newState;
            }

            log.info("Job finished with SUCCESS");
            activeJob.setState(JobState.SUCCESS);
            return null;
          }

          private ManagedItemState finishAction(Action action, BindingScope scope) throws OpsException {
            ManagedItemState newState = null;
            if (action instanceof ConfigureAction) {
              newState = ManagedItemState.ACTIVE;
            }

            if (action instanceof ValidateAction) {
              // TODO: Change state to healthy??
            }

            if (action instanceof DeleteAction) {
              newState = ManagedItemState.DELETED;
            }

            if (action instanceof BackupAction) {
              BackupContext backupContext = scope.getInstance(BackupContext.class);
              backupContext.writeDescriptor();
            }

            return newState;
          }
View Full Code Here

    Machine machine = instanceHelpers.getMachine(mysqlServer);

    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

    boolean required = !OpsContext.isDelete();
    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

    boolean failed = false;

    for (ItemBase dataItem : dataItems) {
      try {
        // Execute the children in a scope
        BindingScope scope = BindingScope.push(machine, target, machineItem, dataItem);
        try {
          OpsContext opsContext = OpsContext.get();
          OperationRecursor.doRecurseChildren(opsContext, controller);
        } finally {
          scope.pop();
        }
      } catch (OpsException e) {
        failed = true;
        log.warn("Error updating machine: " + machine + " with item " + dataItem, e);
      }
View Full Code Here

  @Inject
  Provider<MethodInvoker> invokerProvider;

  public void invoke(Object controller) throws IllegalArgumentException, IllegalAccessException,
      InvocationTargetException {
    final BindingScope scope = BindingScope.get();
    Method method = findTargetMethod(controller, scope);
    if (method == null) {
      throw new IllegalStateException("Cannot find handler for operation on " + controller.getClass());
    }

    MethodInvoker invoker = invokerProvider.get();

    if (scope != null) {
      invoker.addProvider(new Function<Class<?>, Object>() {
        @Override
        public Object apply(Class<?> clazz) {
          return scope.getInstance(clazz);
        }
      });
    }

    invoker.invokeMethod(controller, method);
View Full Code Here

    if (username.equals("postgres") && password == null) {
      password = database.getRootPassword();
    }

    DatabaseTarget dbTarget = database.buildDatabaseTarget(username, password, databaseName);
    BindingScope scope = BindingScope.push(dbTarget);
    try {
      OpsContext opsContext = OpsContext.get();
      OperationRecursor.doRecurseChildren(opsContext, this);
    } finally {
      scope.pop();
    }
  }
View Full Code Here

    }
  }

  @Override
  public void doRecurseOperation() throws OpsException {
    BindingScope scope = null;

    try {
      // TODO: Is this actually safe?
      RecursionState recursionState = this.recursionState;
      this.recursionState = null;

      if (recursionState != null) {
        if (recursionState.preventRecursion) {
          log.warn("Skipping recursion into child items");
          return;
        }
        if (!recursionState.childScope.isEmpty()) {
          scope = BindingScope.push(recursionState.childScope.values());
        }
      }

      OpsContext opsContext = OpsContext.get();
      OperationRecursor.doRecurseChildren(opsContext, this);
    } finally {
      if (scope != null) {
        scope.pop();
      }
    }
  }
View Full Code Here

        getProjectAuthorization());

    return OpsContext.runInContext(opsContext, new CheckedCallable<MetricInfoCollection, Exception>() {
      @Override
      public MetricInfoCollection call() throws Exception {
        BindingScope bindingScope = BindingScope.push(managedItem, managedItem);
        try {
          Object controller = serviceProvider.getController(managedItem);
          MetricConfig metricConfig = opsContext.getMetricInfo(controller);

          return MetricCollector.toMetricInfo(metricConfig);
        } finally {
          bindingScope.pop();
        }
      }
    });
  }
View Full Code Here

TOP

Related Classes of org.platformlayer.ops.BindingScope$BindingScopeStack

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.