Search in sources :

Example 6 with OpsProvider

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

the class GoogleCloudPublicEndpointController method addChildren.

@Override
protected void addChildren() throws OpsException {
    final GoogleCloudPublicEndpoint model = OpsContext.get().getInstance(GoogleCloudPublicEndpoint.class);
    GoogleCloudInstance instance = client.getItem(model.instance, GoogleCloudInstance.class);
    CloudInstanceMapper instanceMapper;
    {
        instanceMapper = injected(CloudInstanceMapper.class);
        instanceMapper.instance = instance;
        addChild(instanceMapper);
    }
    final EnsureFirewallIngress ingress;
    {
        ingress = injected(EnsureFirewallIngress.class);
        ingress.model = model;
        instanceMapper.addChild(ingress);
    }
    {
        OpsProvider<TagChanges> tagChanges = new OpsProvider<TagChanges>() {

            @Override
            public TagChanges get() {
                TagChanges tagChanges = new TagChanges();
                String address = ingress.getPublicAddress();
                if (Strings.isNullOrEmpty(address)) {
                    throw new IllegalStateException();
                }
                EndpointInfo endpoint = new EndpointInfo(address, model.publicPort);
                tagChanges.addTags.add(endpoint.toTag());
                return tagChanges;
            }
        };
        Tagger tagger = injected(Tagger.class);
        tagger.platformLayerKey = model.getKey();
        tagger.tagChangesProvider = tagChanges;
        instanceMapper.addChild(tagger);
        Tagger tagInstance = injected(Tagger.class);
        tagInstance.platformLayerKey = null;
        tagInstance.platformLayerKey = model.instance;
        tagInstance.tagChangesProvider = tagChanges;
        instanceMapper.addChild(tagInstance);
    }
}
Also used : EndpointInfo(org.platformlayer.core.model.EndpointInfo) OpsProvider(org.platformlayer.ops.OpsProvider) Tagger(org.platformlayer.ops.tagger.Tagger) GoogleCloudPublicEndpoint(org.platformlayer.service.cloud.google.model.GoogleCloudPublicEndpoint) TagChanges(org.platformlayer.core.model.TagChanges) GoogleCloudInstance(org.platformlayer.service.cloud.google.model.GoogleCloudInstance)

Example 7 with OpsProvider

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

the class PersistentInstanceMapper method addChildren.

@Override
protected void addChildren() throws OpsException {
    final PersistentInstance model = OpsContext.get().getInstance(PersistentInstance.class);
    {
        // Add tag with instance id to persistent instance (very helpful for DNS service!)
        Tagger tagger = injected(Tagger.class);
        tagger.platformLayerKey = model.getKey();
        tagger.tagChangesProvider = new OpsProvider<TagChanges>() {

            @Override
            public TagChanges get() throws OpsException {
                Machine machine = OpsContext.get().getInstance(Machine.class);
                if (machine == null) {
                    if (OpsContext.isDelete()) {
                        return null;
                    }
                    throw new OpsException("No machine in scope");
                }
                TagChanges changeTags = new TagChanges();
                changeTags.addTags.add(Tag.INSTANCE_KEY.build(machine.getKey()));
                platformLayer.changeTags(model.getKey(), changeTags, null);
                return changeTags;
            }
        };
        addChild(tagger);
    }
}
Also used : OpsException(org.platformlayer.ops.OpsException) PersistentInstance(org.platformlayer.instances.model.PersistentInstance) OpsProvider(org.platformlayer.ops.OpsProvider) Tagger(org.platformlayer.ops.tagger.Tagger) TagChanges(org.platformlayer.core.model.TagChanges) Machine(org.platformlayer.ops.Machine)

Example 8 with OpsProvider

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

the class OpenstackInstanceController method addChildren.

@Override
protected void addChildren() throws OpsException {
    final OpenstackInstance model = OpsContext.get().getInstance(OpenstackInstance.class);
    CloudInstanceMapper instance;
    {
        instance = injected(CloudInstanceMapper.class);
        instance.instance = model;
        addChild(instance);
    }
    {
        OpsProvider<TagChanges> tagChanges = new OpsProvider<TagChanges>() {

            @Override
            public TagChanges get() {
                OpenstackComputeMachine machine = OpsContext.get().getInstance(OpenstackComputeMachine.class);
                TagChanges tagChanges = new TagChanges();
                tagChanges.addTags.add(Tag.INSTANCE_KEY.build(model.getKey()));
                tagChanges.addTags.addAll(machine.buildAddressTags());
                return tagChanges;
            }
        };
        instance.addChild(Tagger.build(model, tagChanges));
    }
// Note: We can't bootstrap an instance, because we can't log in to it,
// because the public key is not our service's public key
// if (model.publicPorts != null) {
// for (int publicPort : model.publicPorts) {
// PublicPorts publicPortForward = injected(PublicPorts.class);
// publicPortForward.port = publicPort;
// publicPortForward.backendItem = model;
// kvm.addChild(publicPortForward);
// }
// }
}
Also used : OpsProvider(org.platformlayer.ops.OpsProvider) OpenstackInstance(org.platformlayer.service.cloud.openstack.model.OpenstackInstance) TagChanges(org.platformlayer.core.model.TagChanges) OpenstackComputeMachine(org.platformlayer.service.cloud.openstack.ops.openstack.OpenstackComputeMachine)

Example 9 with OpsProvider

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

the class OpenstackPublicEndpointController method addChildren.

// @Inject
// ImageFactory imageFactory;
//
@Override
protected void addChildren() throws OpsException {
    final OpenstackPublicEndpoint model = OpsContext.get().getInstance(OpenstackPublicEndpoint.class);
    OpenstackInstance instance = client.getItem(model.instance, OpenstackInstance.class);
    CloudInstanceMapper instanceMapper;
    {
        instanceMapper = injected(CloudInstanceMapper.class);
        instanceMapper.instance = instance;
        addChild(instanceMapper);
    }
    final EnsureFirewallIngress ingress;
    {
        ingress = injected(EnsureFirewallIngress.class);
        ingress.model = model;
        instanceMapper.addChild(ingress);
    }
    {
        OpsProvider<TagChanges> tagChanges = new OpsProvider<TagChanges>() {

            @Override
            public TagChanges get() {
                TagChanges tagChanges = new TagChanges();
                String address = ingress.getPublicAddress();
                if (Strings.isNullOrEmpty(address)) {
                    throw new IllegalStateException();
                }
                EndpointInfo endpoint = new EndpointInfo(address, model.publicPort);
                tagChanges.addTags.add(endpoint.toTag());
                return tagChanges;
            }
        };
        Tagger tagger = injected(Tagger.class);
        tagger.platformLayerKey = model.getKey();
        tagger.tagChangesProvider = tagChanges;
        instanceMapper.addChild(tagger);
        Tagger tagInstance = injected(Tagger.class);
        tagInstance.platformLayerKey = null;
        tagInstance.platformLayerKey = model.instance;
        tagInstance.tagChangesProvider = tagChanges;
        instanceMapper.addChild(tagInstance);
    }
}
Also used : EndpointInfo(org.platformlayer.core.model.EndpointInfo) OpsProvider(org.platformlayer.ops.OpsProvider) OpenstackPublicEndpoint(org.platformlayer.service.cloud.openstack.model.OpenstackPublicEndpoint) Tagger(org.platformlayer.ops.tagger.Tagger) OpenstackInstance(org.platformlayer.service.cloud.openstack.model.OpenstackInstance) TagChanges(org.platformlayer.core.model.TagChanges)

Example 10 with OpsProvider

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

the class SimpleApp method addChildren.

@Override
protected void addChildren() throws OpsException {
    DownloadFileByHash download = addChild(buildDownload());
    File deployed = new File(jettyTemplate.getWarsDeployDir(), getWarName());
    addChild(ManagedSymlink.build(deployed, download.filePath));
    addChild(ManagedDirectory.build(getWorkDir(), "0700"));
    {
        PropertiesConfigFile conf = addChild(PropertiesConfigFile.class);
        conf.filePath = getConfigurationFilePath();
        conf.propertiesSupplier = new OpsProvider<Map<String, String>>() {

            @Override
            public Map<String, String> get() throws OpsException {
                return getConfigurationProperties();
            }
        };
    }
    File contextDir = jettyTemplate.getContextDir();
    ContextTemplate contextTemplate = new ContextTemplate();
    addChild(TemplatedFile.build(contextTemplate, new File(contextDir, "context.xml")));
}
Also used : DownloadFileByHash(org.platformlayer.ops.filesystem.DownloadFileByHash) PropertiesConfigFile(org.platformlayer.ops.standardservice.PropertiesConfigFile) OpsProvider(org.platformlayer.ops.OpsProvider) TemplatedFile(org.platformlayer.ops.filesystem.TemplatedFile) PropertiesConfigFile(org.platformlayer.ops.standardservice.PropertiesConfigFile) File(java.io.File)

Aggregations

OpsProvider (org.platformlayer.ops.OpsProvider)14 TagChanges (org.platformlayer.core.model.TagChanges)9 AddressModel (org.platformlayer.core.model.AddressModel)6 File (java.io.File)5 OpsException (org.platformlayer.ops.OpsException)5 Tagger (org.platformlayer.ops.tagger.Tagger)5 EndpointInfo (org.platformlayer.core.model.EndpointInfo)4 DirectHost (org.platformlayer.service.cloud.direct.model.DirectHost)4 NetworkPoint (org.platformlayer.ops.networks.NetworkPoint)3 NetworkPoolBuilder (org.platformlayer.ops.pool.NetworkPoolBuilder)3 DirectInstance (org.platformlayer.service.cloud.direct.model.DirectInstance)3 IOException (java.io.IOException)2 InetSocketAddress (java.net.InetSocketAddress)2 PlatformLayerKey (org.platformlayer.core.model.PlatformLayerKey)2 OpsTarget (org.platformlayer.ops.OpsTarget)2 NetworkAddressPoolAssignment (org.platformlayer.ops.pool.NetworkAddressPoolAssignment)2 PoolBuilder (org.platformlayer.ops.pool.PoolBuilder)2 SocketAddressPoolAssignment (org.platformlayer.ops.pool.SocketAddressPoolAssignment)2 StaticFilesystemBackedPool (org.platformlayer.ops.pool.StaticFilesystemBackedPool)2 CloudInstanceMapper (org.platformlayer.service.cloud.direct.ops.CloudInstanceMapper)2