use of io.cdap.cdap.common.internal.remote.RemoteClientFactory in project cdap by caskdata.
the class ArtifactLocalizerServiceTest method setupArtifactLocalizerService.
private ArtifactLocalizerService setupArtifactLocalizerService(CConfiguration cConf) {
DiscoveryServiceClient discoveryClient = getInjector().getInstance(DiscoveryServiceClient.class);
RemoteClientFactory remoteClientFactory = new RemoteClientFactory(discoveryClient, new DefaultInternalAuthenticator(new AuthenticationTestContext()));
ArtifactLocalizerService artifactLocalizerService = new ArtifactLocalizerService(cConf, new ArtifactLocalizer(cConf, remoteClientFactory, (namespaceId, retryStrategy) -> {
return new NoOpArtifactManager();
}));
// start the service
artifactLocalizerService.startAndWait();
return artifactLocalizerService;
}
use of io.cdap.cdap.common.internal.remote.RemoteClientFactory in project cdap by caskdata.
the class MasterEnvironmentMain method doMain.
/**
* The actual main method that get invoke through reflection from the {@link #main(String[])} method.
*/
@SuppressWarnings("unused")
public static void doMain(String[] args) throws Exception {
CountDownLatch shutdownLatch = new CountDownLatch(1);
try {
// System wide setup
Thread.setDefaultUncaughtExceptionHandler(new UncaughtExceptionHandler());
// Intercept JUL loggers
SLF4JBridgeHandler.removeHandlersForRootLogger();
SLF4JBridgeHandler.install();
EnvironmentOptions options = new EnvironmentOptions();
String[] runnableArgs = OptionsParser.init(options, args, MasterEnvironmentMain.class.getSimpleName(), ProjectInfo.getVersion().toString(), System.out).toArray(new String[0]);
String runnableClass = options.getRunnableClass();
if (runnableClass == null) {
throw new IllegalArgumentException("Missing runnable class name");
}
CConfiguration cConf = CConfiguration.create();
SConfiguration sConf = SConfiguration.create();
if (options.getExtraConfPath() != null) {
cConf.addResource(new File(options.getExtraConfPath(), "cdap-site.xml").toURI().toURL());
sConf.addResource(new File(options.getExtraConfPath(), "cdap-security.xml").toURI().toURL());
}
SecurityUtil.loginForMasterService(cConf);
Configuration hConf = new Configuration();
// Creates the master environment and load the MasterEnvironmentRunnable class from it.
MasterEnvironment masterEnv = MasterEnvironments.setMasterEnvironment(MasterEnvironments.create(cConf, options.getEnvProvider()));
MasterEnvironmentContext context = MasterEnvironments.createContext(cConf, hConf, masterEnv.getName());
masterEnv.initialize(context);
try {
Class<?> cls = masterEnv.getClass().getClassLoader().loadClass(runnableClass);
if (!MasterEnvironmentRunnable.class.isAssignableFrom(cls)) {
throw new IllegalArgumentException("Runnable class " + runnableClass + " is not an instance of " + MasterEnvironmentRunnable.class);
}
RemoteClientFactory remoteClientFactory = new RemoteClientFactory(masterEnv.getDiscoveryServiceClientSupplier().get(), getInternalAuthenticator(cConf), getRemoteAuthenticator(cConf));
MasterEnvironmentRunnableContext runnableContext = new DefaultMasterEnvironmentRunnableContext(context.getLocationFactory(), remoteClientFactory);
@SuppressWarnings("unchecked") MasterEnvironmentRunnable runnable = masterEnv.createRunnable(runnableContext, (Class<? extends MasterEnvironmentRunnable>) cls);
AtomicBoolean completed = new AtomicBoolean();
Runtime.getRuntime().addShutdownHook(new Thread(() -> {
if (!completed.get()) {
runnable.stop();
Uninterruptibles.awaitUninterruptibly(shutdownLatch, 30, TimeUnit.SECONDS);
}
Optional.ofNullable(tokenManager).ifPresent(TokenManager::stopAndWait);
}));
runnable.run(runnableArgs);
completed.set(true);
} finally {
masterEnv.destroy();
}
} catch (Exception e) {
LOG.error("Failed to execute with arguments {}", Arrays.toString(args), e);
throw e;
} finally {
shutdownLatch.countDown();
}
}
use of io.cdap.cdap.common.internal.remote.RemoteClientFactory in project cdap by caskdata.
the class ArtifactCacheHttpHandlerInternal method fetchArtifact.
@GET
@Path("peers/{peer}/namespaces/{namespace-id}/artifacts/{artifact-name}/versions/{artifact-version}")
public void fetchArtifact(HttpRequest request, HttpResponder responder, @PathParam("peer") String peer, @PathParam("namespace-id") String namespaceId, @PathParam("artifact-name") String artifactName, @PathParam("artifact-version") String artifactVersion) throws Exception {
ArtifactId artifactId = new ArtifactId(namespaceId, artifactName, artifactVersion);
try {
String endpoint = tetheringStore.getPeer(peer).getEndpoint();
RemoteClientFactory factory = new RemoteClientFactory(new NoOpDiscoveryServiceClient(endpoint), new NoOpInternalAuthenticator(), remoteAuthenticator);
HttpRequestConfig config = new DefaultHttpRequestConfig(true);
RemoteClient remoteClient = factory.createRemoteClient("", config, Constants.Gateway.INTERNAL_API_VERSION_3);
File artifactPath = cache.getArtifact(artifactId, peer, remoteClient);
Location artifactLocation = Locations.toLocation(artifactPath);
responder.sendContent(HttpResponseStatus.OK, new LocationBodyProducer(artifactLocation), new DefaultHttpHeaders().add(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_OCTET_STREAM));
} catch (Exception ex) {
if (ex instanceof HttpErrorStatusProvider) {
HttpResponseStatus status = HttpResponseStatus.valueOf(((HttpErrorStatusProvider) ex).getStatusCode());
responder.sendString(status, exceptionToJson(ex));
} else {
responder.sendString(HttpResponseStatus.INTERNAL_SERVER_ERROR, exceptionToJson(ex));
}
}
}
use of io.cdap.cdap.common.internal.remote.RemoteClientFactory in project cdap by caskdata.
the class OAuthMacroEvaluatorTest method init.
@BeforeClass
public static void init() throws Exception {
httpService = NettyHttpService.builder("OAuthTest").setHttpHandlers(new OAuthHandler(ImmutableMap.of(PROVIDER, ImmutableMap.of(CREDENTIAL_ID, new OAuthInfo("accessToken", "bearer"))))).build();
httpService.start();
InMemoryDiscoveryService discoveryService = new InMemoryDiscoveryService();
String discoveryName = ServiceDiscoverable.getName(NamespaceId.SYSTEM.getNamespace(), Constants.PIPELINEID, ProgramType.SERVICE, Constants.STUDIO_SERVICE_NAME);
discoveryService.register(new Discoverable(discoveryName, httpService.getBindAddress()));
RemoteClientFactory remoteClientFactory = new RemoteClientFactory(discoveryService, new DefaultInternalAuthenticator(new AuthenticationTestContext()));
serviceDiscoverer = new AbstractServiceDiscoverer(NamespaceId.DEFAULT.app("testapp").spark("testspark")) {
@Override
protected RemoteClientFactory getRemoteClientFactory() {
return remoteClientFactory;
}
};
}
use of io.cdap.cdap.common.internal.remote.RemoteClientFactory in project cdap by caskdata.
the class SystemAppTask method buildTaskSystemAppContext.
private SystemAppTaskContext buildTaskSystemAppContext(Injector injector, String systemAppNamespace, ArtifactId artifactId, ClassLoader artifactClassLoader) {
PreferencesFetcher preferencesFetcher = injector.getInstance(PreferencesFetcher.class);
PluginFinder pluginFinder = injector.getInstance(PluginFinder.class);
SecureStore secureStore = injector.getInstance(SecureStore.class);
ArtifactManagerFactory artifactManagerFactory = injector.getInstance(ArtifactManagerFactory.class);
RemoteClientFactory remoteClientFactory = injector.getInstance(RemoteClientFactory.class);
return new DefaultSystemAppTaskContext(injector.getInstance(CConfiguration.class), preferencesFetcher, pluginFinder, secureStore, systemAppNamespace, artifactId, artifactClassLoader, artifactManagerFactory, Constants.Service.TASK_WORKER, remoteClientFactory);
}
Aggregations