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();
}
}
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();
}
}
});
}
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();
}
}
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;
}
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();
}
}
}
Aggregations