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);
}
}
}
}
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;
}
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);
}
}
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;
}
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);
}
}
Aggregations