use of org.apache.twill.discovery.Discoverable in project cdap by caskdata.
the class ServiceDiscoveredCodec method serialize.
@Override
public JsonElement serialize(ServiceDiscovered serviceDiscovered, Type typeOfSrc, JsonSerializationContext context) {
JsonArray object = new JsonArray();
for (Discoverable discoverable : serviceDiscovered) {
JsonObject discoverableJson = new JsonObject();
discoverableJson.addProperty("host", discoverable.getSocketAddress().getHostName());
discoverableJson.addProperty("port", discoverable.getSocketAddress().getPort());
object.add(discoverableJson);
}
return object;
}
use of org.apache.twill.discovery.Discoverable in project cdap by caskdata.
the class DiscoverableCodec method deserialize.
@Override
public Discoverable deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException {
JsonObject jsonObj = json.getAsJsonObject();
String service = jsonObj.get("service").getAsString();
String hostname = jsonObj.get("hostname").getAsString();
int port = jsonObj.get("port").getAsInt();
InetSocketAddress address = new InetSocketAddress(hostname, port);
byte[] payload = context.deserialize(jsonObj.get("payload"), BYTE_ARRAY_TYPE);
return new Discoverable(service, address, payload);
}
use of org.apache.twill.discovery.Discoverable in project cdap by caskdata.
the class StreamHttpService method startUp.
@Override
protected void startUp() throws Exception {
LoggingContextAccessor.setLoggingContext(new ServiceLoggingContext(NamespaceId.SYSTEM.getEntityName(), Constants.Logging.COMPONENT_NAME, Constants.Service.STREAMS));
httpService.startAndWait();
discoverable = ResolvingDiscoverable.of(new Discoverable(Constants.Service.STREAMS, httpService.getBindAddress()));
cancellable = discoveryService.register(discoverable);
}
use of org.apache.twill.discovery.Discoverable in project cdap by caskdata.
the class RemoteSystemOperationsService method startUp.
@Override
protected void startUp() throws Exception {
LoggingContextAccessor.setLoggingContext(new ServiceLoggingContext(NamespaceId.SYSTEM.getNamespace(), Constants.Logging.COMPONENT_NAME, Constants.Service.REMOTE_SYSTEM_OPERATION));
LOG.info("Starting RemoteSystemOperationService...");
httpService.startAndWait();
cancellable = discoveryService.register(ResolvingDiscoverable.of(new Discoverable(Constants.Service.REMOTE_SYSTEM_OPERATION, httpService.getBindAddress())));
LOG.info("RemoteSystemOperationService started successfully on {}", httpService.getBindAddress());
}
use of org.apache.twill.discovery.Discoverable in project cdap by caskdata.
the class WebappProgramRunner method run.
@Override
public ProgramController run(Program program, ProgramOptions options) {
try {
ProgramType processorType = program.getType();
Preconditions.checkNotNull(processorType, "Missing processor type");
Preconditions.checkArgument(processorType == ProgramType.WEBAPP, "Only WEBAPP process type is supported");
LOG.info("Initializing Webapp for app {} with jar {}", program.getApplicationId(), program.getJarLocation().getName());
String serviceName = getServiceName(program.getId());
Preconditions.checkNotNull(serviceName, "Cannot determine service name for program %s", program.getName());
LOG.info("Got service name {}", serviceName);
// Start netty server
// TODO: add metrics reporting
JarHttpHandler jarHttpHandler = webappHttpHandlerFactory.createHandler(program.getJarLocation());
NettyHttpService.Builder builder = new CommonNettyHttpServiceBuilder(cConf, program.getId().toString());
builder.addHttpHandlers(ImmutableSet.of(jarHttpHandler));
builder.setUrlRewriter(new WebappURLRewriter(jarHttpHandler));
builder.setHost(hostname.getCanonicalHostName());
NettyHttpService httpService = builder.build();
httpService.startAndWait();
final InetSocketAddress address = httpService.getBindAddress();
RunId runId = ProgramRunners.getRunId(options);
// Register service, and the serving host names.
final List<Cancellable> cancellables = Lists.newArrayList();
LOG.info("Webapp {} running on address {} registering as {}", program.getApplicationId(), address, serviceName);
cancellables.add(serviceAnnouncer.announce(serviceName, address.getPort()));
for (String hname : getServingHostNames(Locations.newInputSupplier(program.getJarLocation()))) {
final String sname = ProgramType.WEBAPP.name().toLowerCase() + "/" + hname;
LOG.info("Webapp {} running on address {} registering as {}", program.getApplicationId(), address, sname);
cancellables.add(discoveryService.register(ResolvingDiscoverable.of(new Discoverable(sname, address))));
}
return new WebappProgramController(program.getId(), runId, httpService, new Cancellable() {
@Override
public void cancel() {
for (Cancellable cancellable : cancellables) {
cancellable.cancel();
}
}
});
} catch (Exception e) {
throw Throwables.propagate(e);
}
}
Aggregations