Search in sources :

Example 6 with BindingScope

use of org.platformlayer.ops.BindingScope in project platformlayer by platformlayer.

the class MysqlConnection method doRecurseOperation.

@Override
public void doRecurseOperation() throws OpsException {
    MysqlServer mysqlServer = platformLayerHelpers.getItem(key, MysqlServer.class);
    String username = this.username;
    if (username == null) {
        username = "root";
        password = mysqlServer.rootPassword;
    }
    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();
    }
}
Also used : MysqlTarget(org.platformlayer.service.mysql.ops.MysqlTarget) OpsContext(org.platformlayer.ops.OpsContext) MysqlServer(org.platformlayer.service.mysql.model.MysqlServer) Machine(org.platformlayer.ops.Machine) BindingScope(org.platformlayer.ops.BindingScope)

Example 7 with BindingScope

use of org.platformlayer.ops.BindingScope in project platformlayer by platformlayer.

the class MetricsResource method getMetrics.

@POST
@Produces({ XML, JSON })
public MetricDataSource getMetrics(final MetricQuery query) throws RepositoryException, OpsException {
    final ItemBase managedItem = getManagedItem();
    final ServiceProvider serviceProvider = getServiceProvider();
    OpsContextBuilder opsContextBuilder = objectInjector.getInstance(OpsContextBuilder.class);
    final OpsContext opsContext = opsContextBuilder.buildTemporaryOpsContext(getServiceType(), getProjectAuthorization());
    return OpsContext.runInContext(opsContext, new CheckedCallable<MetricDataSource, Exception>() {

        @Override
        public MetricDataSource call() throws Exception {
            BindingScope bindingScope = BindingScope.push(managedItem, managedItem);
            try {
                MetricDataSource metrics = serviceProvider.getMetricValues(managedItem, query);
                return metrics;
            } finally {
                bindingScope.pop();
            }
        }
    });
}
Also used : MetricDataSource(org.platformlayer.metrics.model.MetricDataSource) ItemBase(org.platformlayer.core.model.ItemBase) ServiceProvider(org.platformlayer.xaas.services.ServiceProvider) OpsContext(org.platformlayer.ops.OpsContext) RepositoryException(org.platformlayer.RepositoryException) OpsException(org.platformlayer.ops.OpsException) OpsContextBuilder(org.platformlayer.ops.tasks.OpsContextBuilder) BindingScope(org.platformlayer.ops.BindingScope) POST(javax.ws.rs.POST) Produces(javax.ws.rs.Produces)

Example 8 with BindingScope

use of org.platformlayer.ops.BindingScope in project platformlayer by platformlayer.

the class DatabaseConnection method doRecurseOperation.

@Override
public void doRecurseOperation() throws OpsException {
    ItemBase server = platformLayer.getItem(serverKey);
    DatabaseServer database = providers.toInterface(server, DatabaseServer.class);
    String username = this.username;
    if (username == null) {
        username = database.getRootUsername();
    }
    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();
    }
}
Also used : ItemBase(org.platformlayer.core.model.ItemBase) DatabaseServer(org.platformlayer.ops.databases.DatabaseServer) DatabaseTarget(org.platformlayer.ops.databases.DatabaseTarget) OpsContext(org.platformlayer.ops.OpsContext) BindingScope(org.platformlayer.ops.BindingScope)

Example 9 with BindingScope

use of org.platformlayer.ops.BindingScope in project platformlayer by platformlayer.

the class ForEach method processDataItems.

private boolean processDataItems(Object controller, List<ItemBase> dataItems, ItemBase machineItem, Machine machine, OpsTarget target) {
    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);
        }
    }
    return failed;
}
Also used : OpsException(org.platformlayer.ops.OpsException) ItemBase(org.platformlayer.core.model.ItemBase) OpsContext(org.platformlayer.ops.OpsContext) BindingScope(org.platformlayer.ops.BindingScope)

Example 10 with BindingScope

use of org.platformlayer.ops.BindingScope in project platformlayer by platformlayer.

the class OpsTreeBase method doRecurseOperation.

@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();
        }
    }
}
Also used : OpsContext(org.platformlayer.ops.OpsContext) BindingScope(org.platformlayer.ops.BindingScope)

Aggregations

BindingScope (org.platformlayer.ops.BindingScope)11 OpsContext (org.platformlayer.ops.OpsContext)10 ItemBase (org.platformlayer.core.model.ItemBase)7 OpsException (org.platformlayer.ops.OpsException)5 Machine (org.platformlayer.ops.Machine)4 RepositoryException (org.platformlayer.RepositoryException)3 OpsTarget (org.platformlayer.ops.OpsTarget)3 ServiceProvider (org.platformlayer.xaas.services.ServiceProvider)3 Produces (javax.ws.rs.Produces)2 OpsContextBuilder (org.platformlayer.ops.tasks.OpsContextBuilder)2 TimeSpan (com.fathomdb.TimeSpan)1 Method (java.lang.reflect.Method)1 List (java.util.List)1 GET (javax.ws.rs.GET)1 POST (javax.ws.rs.POST)1 WebApplicationException (javax.ws.rs.WebApplicationException)1 Action (org.platformlayer.core.model.Action)1 BackupAction (org.platformlayer.core.model.BackupAction)1 ConfigureAction (org.platformlayer.core.model.ConfigureAction)1 DeleteAction (org.platformlayer.core.model.DeleteAction)1