Search in sources :

Example 16 with Machine

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

the class SolrClusterController method getMachines.

@Override
public List<Machine> getMachines(boolean required) throws OpsException {
    Filter parentFilter = TagFilter.byTag(Tag.buildParentTag(model.getKey()));
    List<Machine> machines = Lists.newArrayList();
    for (SolrServer server : platformLayer.listItems(SolrServer.class, parentFilter)) {
        Machine machine = instances.getMachine(server, required);
        if (machine != null) {
            machines.add(machine);
        }
    }
    return machines;
}
Also used : TagFilter(org.platformlayer.TagFilter) Filter(org.platformlayer.Filter) SolrServer(org.platformlayer.service.solr.model.SolrServer) Machine(org.platformlayer.ops.Machine)

Example 17 with Machine

use of org.platformlayer.ops.Machine 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 18 with Machine

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

the class NginxFrontendDns method buildItemTemplate.

@Override
protected DnsRecord buildItemTemplate() throws OpsException {
    // TODO: Idempotency etc
    // Machine machine = OpsContext.get().getInstance(Machine.class);
    NginxService nginxService = OpsContext.get().getInstance(NginxService.class);
    NginxFrontend nginxFrontend = OpsContext.get().getInstance(NginxFrontend.class);
    Machine machine = instanceHelpers.getMachine(nginxService);
    String address = machine.getNetworkPoint().getBestAddress(NetworkPoint.forPublicInternet());
    DnsRecord record = new DnsRecord();
    record.setDnsName(nginxFrontend.hostname);
    record.getAddress().add(address);
    Tag parentTag = Tag.buildParentTag(nginxFrontend.getKey());
    record.getTags().add(parentTag);
    Tag uniqueTag = UniqueTag.build(nginxService, nginxFrontend);
    record.getTags().add(uniqueTag);
    record.key = PlatformLayerKey.fromId(nginxFrontend.hostname);
    return record;
}
Also used : NginxFrontend(org.openstack.service.nginx.model.NginxFrontend) UniqueTag(org.platformlayer.ops.UniqueTag) Tag(org.platformlayer.core.model.Tag) DnsRecord(org.platformlayer.dns.model.DnsRecord) Machine(org.platformlayer.ops.Machine) NginxService(org.openstack.service.nginx.model.NginxService)

Example 19 with Machine

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

the class SiteTemplateData method resolveBackends.

private List<BackendModel> resolveBackends(List<NginxBackend> backends) throws OpsException {
    List<BackendModel> resolved = Lists.newArrayList();
    for (NginxBackend backend : backends) {
        ItemBase backendItem = platformLayer.getItem(backend.backend);
        Machine backendMachine = instances.getMachine(backendItem);
        int port = 0;
        if (port == 0) {
            port = 80;
        }
        // if (address.contains(":")) {
        // resolved.addAll(resolvePlatformLayer(address));
        // continue;
        // }
        // TODO: We need to register a dependency on the resolved item
        BackendModel model = new BackendModel();
        model.address = backendMachine.getNetworkPoint().getBestAddress(NetworkPoint.forTargetInContext());
        model.port = port;
        resolved.add(model);
    }
    return resolved;
}
Also used : NginxBackend(org.openstack.service.nginx.model.NginxBackend) ItemBase(org.platformlayer.core.model.ItemBase) Machine(org.platformlayer.ops.Machine) NetworkPoint(org.platformlayer.ops.networks.NetworkPoint)

Example 20 with Machine

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

the class InstanceBuilder method doOperation.

@Handler
public void doOperation() throws OpsException, IOException {
    ItemBase item = ops.getInstance(ItemBase.class);
    Tag parentTag = Tag.buildParentTag(item.getKey());
    PersistentInstance persistentInstanceTemplate = buildPersistentInstanceTemplate();
    persistentInstanceTemplate.getTags().add(parentTag);
    // Set during doOperation
    Machine machine = null;
    PersistentInstance persistentInstance = null;
    InstanceBase instance = null;
    OpsTarget target = null;
    persistentInstance = getOrCreate(parentTag, persistentInstanceTemplate);
    if (persistentInstance != null) {
        // We have to connect to the underlying machine not-via-DNS for Dns service => use instance id
        // TODO: Should we always use the instance id??
        instance = instances.findInstance(persistentInstance);
        if (instance == null && !OpsContext.isDelete()) {
            // A machine has not (yet) been assigned
            throw new OpsException("Machine is not yet built").setRetry(TimeSpan.ONE_MINUTE);
        }
    }
    if (instance != null) {
        machine = cloudHelpers.toMachine(instance);
    }
    if (addTagToManaged && !OpsContext.isDelete()) {
        // Add tag with instance id to persistent instance (very helpful for
        // DNS service!)
        PlatformLayerKey machineKey = machine.getKey();
        platformLayer.addTag(item.getKey(), Tag.INSTANCE_KEY.build(machineKey));
    }
    SshKey sshKey = service.getSshKey();
    if (machine != null) {
        if (OpsContext.isDelete()) {
            target = null;
            machine = null;
        } else {
            target = machine.getTarget(sshKey);
        }
    }
    RecursionState recursion = getRecursionState();
    if (OpsContext.isDelete() && machine == null) {
        // Don't recurse into no machine :-)
        recursion.setPreventRecursion(true);
    }
    recursion.pushChildScope(Machine.class, machine);
    recursion.pushChildScope(PersistentInstance.class, persistentInstance);
    recursion.pushChildScope(InstanceBase.class, instance);
    recursion.pushChildScope(OpsTarget.class, target);
}
Also used : SshKey(org.platformlayer.ops.helpers.SshKey) OpsTarget(org.platformlayer.ops.OpsTarget) OpsException(org.platformlayer.ops.OpsException) PersistentInstance(org.platformlayer.instances.model.PersistentInstance) ItemBase(org.platformlayer.core.model.ItemBase) PlatformLayerKey(org.platformlayer.core.model.PlatformLayerKey) Tag(org.platformlayer.core.model.Tag) InstanceBase(org.platformlayer.core.model.InstanceBase) Machine(org.platformlayer.ops.Machine) Handler(org.platformlayer.ops.Handler)

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