Search in sources :

Example 11 with Machine

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

the class DirectCloudUtils method toTarget.

public OpsTarget toTarget(DirectHost host) throws OpsException {
    NetworkPoint address = NetworkPoint.forPublicHostname(host.host);
    Machine hostMachine = new OpaqueMachine(address);
    OpsTarget hostTarget = hostMachine.getTarget(service.getSshKey());
    return hostTarget;
}
Also used : OpsTarget(org.platformlayer.ops.OpsTarget) OpaqueMachine(org.platformlayer.ops.OpaqueMachine) NetworkPoint(org.platformlayer.ops.networks.NetworkPoint) Machine(org.platformlayer.ops.Machine) OpaqueMachine(org.platformlayer.ops.OpaqueMachine)

Example 12 with Machine

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

the class DirectTarget method doRecurseOperation.

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

Example 13 with Machine

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

the class OpenstackBackupContextFactory method build.

@Override
public OpenstackBackupContext build(ItemBase item) throws OpsException {
    Machine machine = instances.findMachine(item);
    if (machine == null) {
        throw new OpsException("Cannot determine machine for: " + item);
    }
    StorageConfiguration storageConfiguration = cloud.getStorageConfiguration(machine);
    return build(storageConfiguration);
}
Also used : OpsException(org.platformlayer.ops.OpsException) OpenstackStorageConfiguration(org.platformlayer.service.cloud.openstack.ops.OpenstackStorageConfiguration) StorageConfiguration(org.platformlayer.ops.machines.StorageConfiguration) Machine(org.platformlayer.ops.Machine)

Example 14 with Machine

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

the class ForEach method doRecursion.

public void doRecursion(Object controller, SshKey sshKey, Class<? extends ItemBase> machineItemClass, Class<? extends ItemBase> dataItemClass) throws OpsException {
    boolean failed = false;
    OpsContext ops = OpsContext.get();
    List<ItemBase> dataItems = Lists.newArrayList();
    ItemBase contextDataItem = ops.getInstance(dataItemClass);
    if (contextDataItem != null) {
        dataItems.add(contextDataItem);
    } else {
        for (ItemBase dataItem : platformLayer.listItems(dataItemClass)) {
            dataItems.add(dataItem);
        }
    }
    Object contextMachine = ops.getInstance(machineItemClass);
    if (contextMachine != null) {
        // We are presumably building the machine item
        PlatformLayerKey targetItemKey = ops.getJobRecord().getTargetItemKey();
        ItemBase machineItem = (ItemBase) contextMachine;
        if (!Objects.equal(targetItemKey, machineItem.getKey())) {
            throw new OpsException("Expected to find same model");
        }
        Machine machine = instances.findMachine(machineItem);
        if (machine == null) {
            log.warn("Server instance not found: " + contextMachine);
            failed = true;
        } else {
            OpsTarget target = machine.getTarget(sshKey);
            failed |= processDataItems(controller, dataItems, machineItem, machine, target);
        }
    } else {
        // We are building a data item
        for (ItemBase machineItem : platformLayer.listItems(machineItemClass)) {
            if (machineItem.getState() != ManagedItemState.ACTIVE) {
                log.warn("Machine not yet active: " + machineItem);
                failed = true;
                continue;
            }
            Machine machine = instances.findMachine(machineItem);
            if (machine == null) {
                log.warn("Server instance not found: " + machineItem);
                failed = true;
                continue;
            }
            OpsTarget target = machine.getTarget(sshKey);
            failed |= processDataItems(controller, dataItems, machineItem, machine, target);
        }
    }
    if (failed) {
        throw new OpsException("Could not update all servers").setRetry(TimeSpan.ONE_MINUTE);
    }
}
Also used : OpsException(org.platformlayer.ops.OpsException) OpsTarget(org.platformlayer.ops.OpsTarget) ItemBase(org.platformlayer.core.model.ItemBase) PlatformLayerKey(org.platformlayer.core.model.PlatformLayerKey) OpsContext(org.platformlayer.ops.OpsContext) Machine(org.platformlayer.ops.Machine)

Example 15 with Machine

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

the class ZookeeperInstanceModel method getCluster.

public Cluster getCluster() throws OpsException {
    Cluster cluster = new Cluster();
    for (ZookeeperServer server : getClusterServers()) {
        // TODO: Do keys need to be sequential
        ClusterServer model = new ClusterServer();
        model.key = server.clusterId;
        // TODO: What do we do about machines that don't yet have an ip?
        NetworkPoint targetNetworkPoint = NetworkPoint.forPublicInternet();
        Machine sourceMachine = instances.getMachine(server);
        String address = sourceMachine.getNetworkPoint().getBestAddress(targetNetworkPoint);
        model.ip = address;
        model.dnsName = ZookeeperUtils.buildDnsName(server);
        cluster.servers.add(model);
    }
    return cluster;
}
Also used : ZookeeperServer(org.platformlayer.service.zookeeper.model.ZookeeperServer) NetworkPoint(org.platformlayer.ops.networks.NetworkPoint) Machine(org.platformlayer.ops.Machine)

Aggregations

Machine (org.platformlayer.ops.Machine)27 OpsException (org.platformlayer.ops.OpsException)13 OpsTarget (org.platformlayer.ops.OpsTarget)12 ItemBase (org.platformlayer.core.model.ItemBase)7 NetworkPoint (org.platformlayer.ops.networks.NetworkPoint)7 OpsContext (org.platformlayer.ops.OpsContext)5 SshKey (org.platformlayer.ops.helpers.SshKey)5 InetAddress (java.net.InetAddress)4 PlatformLayerKey (org.platformlayer.core.model.PlatformLayerKey)4 Tag (org.platformlayer.core.model.Tag)4 BindingScope (org.platformlayer.ops.BindingScope)4 Handler (org.platformlayer.ops.Handler)4 OpaqueMachine (org.platformlayer.ops.OpaqueMachine)4 List (java.util.List)3 MachineCreationRequest (org.platformlayer.ops.MachineCreationRequest)3 URI (java.net.URI)2 URISyntaxException (java.net.URISyntaxException)2 TagChanges (org.platformlayer.core.model.TagChanges)2 Tags (org.platformlayer.core.model.Tags)2 ServiceType (org.platformlayer.ids.ServiceType)2