Search in sources :

Example 1 with EndpointInfo

use of org.platformlayer.core.model.EndpointInfo 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 2 with EndpointInfo

use of org.platformlayer.core.model.EndpointInfo in project platformlayer by platformlayer.

the class OpenItem method runCommand.

@Override
public Object runCommand() throws PlatformLayerClientException {
    PlatformLayerClient client = getPlatformLayerClient();
    PlatformLayerKey key = path.resolve(getContext());
    UntypedItem untypedItem = client.getItemUntyped(key, getFormat());
    List<EndpointInfo> endpointList = EndpointInfo.getEndpoints(untypedItem.getTags());
    Set<EndpointInfo> endpoints = Sets.newHashSet(endpointList);
    EndpointInfo bestEndpoint = null;
    for (EndpointInfo candidate : endpoints) {
        if (bestEndpoint == null) {
            bestEndpoint = candidate;
        } else {
            throw new IllegalArgumentException("Cannot choose between: " + bestEndpoint + " and " + candidate);
        }
    }
    ClientAction action = null;
    if (bestEndpoint != null) {
        // TODO: How do we want to do this? A new tag??
        String id = key.getServiceType().getKey() + ":" + key.getItemType().getKey();
        if (id.equals("jenkins:jenkinsService")) {
            action = new ClientAction(ClientAction.ClientActionType.BROWSER, "http://" + bestEndpoint.publicIp + ":" + bestEndpoint.publicIp);
        }
    }
    return action;
}
Also used : PlatformLayerClient(org.platformlayer.PlatformLayerClient) ClientAction(com.fathomdb.cli.output.ClientAction) UntypedItem(org.platformlayer.common.UntypedItem) EndpointInfo(org.platformlayer.core.model.EndpointInfo) PlatformLayerKey(org.platformlayer.core.model.PlatformLayerKey)

Example 3 with EndpointInfo

use of org.platformlayer.core.model.EndpointInfo 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 4 with EndpointInfo

use of org.platformlayer.core.model.EndpointInfo in project platformlayer by platformlayer.

the class PlatformLayerTestContext method getEndpoint.

private InetSocketAddress getEndpoint(ItemBase item, boolean unique) {
    List<EndpointInfo> endpoints = EndpointInfo.getEndpoints(item.getTags());
    if (unique) {
        if (endpoints.size() != 1) {
            throw new IllegalStateException("Expected exactly one endpoint");
        }
        System.out.println("Found endpoint: " + endpoints.get(0));
    } else {
        if (endpoints.size() == 0) {
            throw new IllegalStateException("Expected at least one endpoint");
        }
        System.out.println("Found endpoints: " + endpoints + "; choosing: " + endpoints.get(0));
    }
    InetSocketAddress socketAddress = toSocketAddress(endpoints.get(0));
    return socketAddress;
}
Also used : EndpointInfo(org.platformlayer.core.model.EndpointInfo) InetSocketAddress(java.net.InetSocketAddress)

Example 5 with EndpointInfo

use of org.platformlayer.core.model.EndpointInfo 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)

Aggregations

EndpointInfo (org.platformlayer.core.model.EndpointInfo)12 OpsException (org.platformlayer.ops.OpsException)7 TagChanges (org.platformlayer.core.model.TagChanges)4 OpsProvider (org.platformlayer.ops.OpsProvider)4 Tagger (org.platformlayer.ops.tagger.Tagger)4 InetSocketAddress (java.net.InetSocketAddress)3 Handler (org.platformlayer.ops.Handler)3 PlatformLayerClient (org.platformlayer.PlatformLayerClient)2 UntypedItem (org.platformlayer.common.UntypedItem)2 ItemBase (org.platformlayer.core.model.ItemBase)2 PlatformLayerKey (org.platformlayer.core.model.PlatformLayerKey)2 PublicEndpointBase (org.platformlayer.core.model.PublicEndpointBase)2 DnsRecord (org.platformlayer.dns.model.DnsRecord)2 ClientAction (com.fathomdb.cli.output.ClientAction)1 InetAddress (java.net.InetAddress)1 List (java.util.List)1 Map (java.util.Map)1 PlatformLayerClientException (org.platformlayer.PlatformLayerClientException)1 AddressModel (org.platformlayer.core.model.AddressModel)1 Tag (org.platformlayer.core.model.Tag)1