Search in sources :

Example 6 with Handler

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

the class ZookeeperStatusChecker method handler.

@Handler
public void handler(OpsTarget target, ZookeeperServer zookeeperServer) throws OpsException {
    if (OpsContext.isConfigure() || OpsContext.isValidate()) {
        int port = ZookeeperConstants.ZK_PUBLIC_PORT;
        List<EndpointInfo> endpoints = EndpointInfo.findEndpoints(zookeeperServer.getTags(), port);
        EndpointInfo endpoint = EndpointChooser.any().choose(endpoints);
        if (endpoint == null) {
            throw new OpsException("Cannot find endpoint for zookeeper");
        }
        InetSocketAddress socketAddress = endpoint.asSocketAddress();
        {
            ZookeeperResponse response;
            try {
                // IPV6 requires ipsec; use the IPV4 loopback instead
                socketAddress = new InetSocketAddress(InetAddresses.forString("127.0.0.1"), socketAddress.getPort());
                response = ZookeeperUtils.sendCommand(target, socketAddress, "ruok");
                Deviations.assertEquals("imok", response.getRaw(), "Zookeeper ruok status");
            } catch (OpsException e) {
                Deviations.fail("Unable to connect to zookeeper", e);
            }
        }
        {
            ZookeeperResponse response;
            try {
                response = ZookeeperUtils.sendCommand(target, socketAddress, "srvr");
                Map<String, String> responseMap = response.asMap();
                String mode = responseMap.get("Mode");
                Deviations.assertIn(Arrays.asList("follower", "leader"), mode, "Zookeeper mode");
            } catch (OpsException e) {
                Deviations.fail("Unable to connect to zookeeper", e);
            }
        }
    }
}
Also used : EndpointInfo(org.platformlayer.core.model.EndpointInfo) OpsException(org.platformlayer.ops.OpsException) ZookeeperResponse(org.platformlayer.service.zookeeper.ops.ZookeeperUtils.ZookeeperResponse) InetSocketAddress(java.net.InetSocketAddress) Map(java.util.Map) Handler(org.platformlayer.ops.Handler)

Example 7 with Handler

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

the class ScheduleController method handler.

@Handler
public void handler() throws OpsException {
    if (OpsContext.isConfigure()) {
        String key = model.getKey().getUrl();
        PlatformLayerKey target = model.targetItem;
        PlatformLayerEndpointInfo endpoint = platformLayer.getEndpointInfo(target);
        JobSchedule schedule = model.schedule;
        Action action = model.action;
        actionScheduler.putJob(key, endpoint, schedule, target, action);
    }
}
Also used : Action(org.platformlayer.core.model.Action) PlatformLayerEndpointInfo(org.platformlayer.PlatformLayerEndpointInfo) JobSchedule(org.platformlayer.core.model.JobSchedule) PlatformLayerKey(org.platformlayer.core.model.PlatformLayerKey) Handler(org.platformlayer.ops.Handler)

Example 8 with Handler

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

the class SolrCore method handler.

@Handler
public void handler(OpsTarget target) throws OpsException {
    SolrCoreHelpers helper = new SolrCoreHelpers(target, key);
    if (OpsContext.isConfigure()) {
        // TODO: only reload if changed??
        SolrCoreStatus status0 = helper.getStatus();
        helper.reload();
        // TODO: It looks like reload is async; hopefully this check deals with that
        SolrCoreStatus status1 = helper.getStatus();
        while (true) {
            String startTime0 = status0.getStartTime();
            String startTime1 = status1.getStartTime();
            if (!Objects.equal(startTime0, startTime1)) {
                break;
            }
            OpsSystem.safeSleep(TimeSpan.ONE_SECOND);
        }
    }
}
Also used : SolrCoreStatus(org.platformlayer.service.solr.ops.SolrCoreHelpers.SolrCoreStatus) Handler(org.platformlayer.ops.Handler)

Example 9 with Handler

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

the class TomcatServerBootstrap method doOperation.

@Handler
public void doOperation(OpsTarget target) throws OpsException {
    File webappsDir = new File("/var/lib/tomcat6/webapps");
    target.mv(webappsDir, new File("/var/lib/tomcat6/webapps.default"));
    target.mkdir(webappsDir, "775");
    target.chown(webappsDir, "tomcat6", "tomcat6", false, false);
    // We remove the root context, but we leave the ones relating to the manager app
    File rootContext = new File("/etc/tomcat6/Catalina/localhost/ROOT.xml");
    target.rm(rootContext);
// File contextsDir = new File("/etc/jetty/contexts");
// target.mv(contextsDir, new File("/etc/jetty/contexts.default"));
// target.mkdir(contextsDir, "755");
// target.chown(contextsDir, "root", "root", false);
}
Also used : File(java.io.File) Handler(org.platformlayer.ops.Handler)

Example 10 with Handler

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

the class ApacheBootstrap method handler.

@Handler
public void handler() throws OpsException {
    OpsTarget target = OpsContext.get().getInstance(OpsTarget.class);
    target.rm(new File("/etc/apache2/sites-enabled/000-default"));
}
Also used : OpsTarget(org.platformlayer.ops.OpsTarget) File(java.io.File) Handler(org.platformlayer.ops.Handler)

Aggregations

Handler (org.platformlayer.ops.Handler)58 File (java.io.File)21 Command (org.platformlayer.ops.Command)17 OpsException (org.platformlayer.ops.OpsException)17 OpsTarget (org.platformlayer.ops.OpsTarget)17 Tag (org.platformlayer.core.model.Tag)8 PlatformLayerKey (org.platformlayer.core.model.PlatformLayerKey)5 SshKey (org.platformlayer.ops.helpers.SshKey)5 Machine (org.platformlayer.ops.Machine)4 PublicKey (java.security.PublicKey)3 Action (org.platformlayer.core.model.Action)3 EndpointInfo (org.platformlayer.core.model.EndpointInfo)3 ItemBase (org.platformlayer.core.model.ItemBase)3 Tags (org.platformlayer.core.model.Tags)3 MachineCreationRequest (org.platformlayer.ops.MachineCreationRequest)3 Map (java.util.Map)2 OpenstackComputeClient (org.openstack.client.common.OpenstackComputeClient)2 SecurityGroup (org.openstack.model.compute.SecurityGroup)2 Server (org.openstack.model.compute.Server)2 PlatformLayerClientException (org.platformlayer.PlatformLayerClientException)2