use of io.cdap.cdap.proto.id.ServiceId in project cdap by cdapio.
the class QueryClientTest method testAll.
@Test
public void testAll() throws Exception {
NamespaceId namespace = new NamespaceId("queryClientTestNamespace");
NamespaceId otherNamespace = new NamespaceId("queryClientOtherNamespace");
namespaceClient.create(new NamespaceMeta.Builder().setName(namespace).build());
ApplicationId app = namespace.app(FakeApp.NAME);
ServiceId service = app.service(DatasetWriterService.NAME);
DatasetId dataset = namespace.dataset(FakeApp.DS_NAME);
appClient.deploy(namespace, createAppJarFile(FakeApp.class));
try {
programClient.start(service);
assertProgramRunning(programClient, service);
// Write some data through the service
Map<String, String> data = new HashMap<>();
data.put("bob", "123");
data.put("joe", "321");
URL writeURL = new URL(serviceClient.getServiceURL(service), "write");
HttpResponse response = HttpRequests.execute(HttpRequest.post(writeURL).withBody(new Gson().toJson(data)).build(), new DefaultHttpRequestConfig(false));
Assert.assertEquals(200, response.getResponseCode());
executeBasicQuery(namespace, FakeApp.DS_NAME);
exploreClient.disableExploreDataset(dataset).get();
try {
queryClient.execute(namespace, "select * from " + FakeApp.DS_NAME).get();
Assert.fail("Explore Query should have thrown an ExecutionException since explore is disabled");
} catch (ExecutionException e) {
// ignored
}
exploreClient.enableExploreDataset(dataset).get();
executeBasicQuery(namespace, FakeApp.DS_NAME);
try {
queryClient.execute(otherNamespace, "show tables").get();
Assert.fail("Explore Query should have thrown an ExecutionException since the database should not exist");
} catch (ExecutionException e) {
// expected
}
} finally {
programClient.stop(service);
assertProgramStopped(programClient, service);
try {
appClient.delete(app);
} catch (Exception e) {
LOG.error("Error deleting app {} during test cleanup.", e);
}
}
}
use of io.cdap.cdap.proto.id.ServiceId in project cdap by caskdata.
the class HttpEndpointPrefixCompleter method complete.
@Override
public int complete(String buffer, int cursor, List<CharSequence> candidates) {
Map<String, String> arguments = ArgumentParser.getArguments(buffer, PATTERN);
ProgramIdArgument programIdArgument = ArgumentParser.parseProgramId(arguments.get(SERVICE_ID));
if (programIdArgument != null) {
ServiceId service;
if (arguments.get(APP_VERSION) == null) {
service = cliConfig.getCurrentNamespace().app(programIdArgument.getAppId()).service(programIdArgument.getProgramId());
} else {
service = cliConfig.getCurrentNamespace().app(programIdArgument.getAppId(), arguments.get(APP_VERSION)).service(programIdArgument.getProgramId());
}
completer.setEndpoints(getEndpoints(service, arguments.get(METHOD)));
} else {
completer.setEndpoints(Collections.<String>emptyList());
}
return super.complete(buffer, cursor, candidates);
}
use of io.cdap.cdap.proto.id.ServiceId in project cdap by caskdata.
the class HttpMethodPrefixCompleter method complete.
@Override
public int complete(String buffer, int cursor, List<CharSequence> candidates) {
Map<String, String> arguments = ArgumentParser.getArguments(buffer, PATTERN);
ProgramIdArgument programIdArgument = ArgumentParser.parseProgramId(arguments.get(SERVICE_ID));
if (programIdArgument != null) {
ServiceId service;
if (arguments.get(APP_VERSION) == null) {
service = cliConfig.getCurrentNamespace().app(programIdArgument.getAppId()).service(programIdArgument.getProgramId());
} else {
service = cliConfig.getCurrentNamespace().app(programIdArgument.getAppId(), arguments.get(APP_VERSION)).service(programIdArgument.getProgramId());
}
completer.setEndpoints(getMethods(service));
} else {
completer.setEndpoints(Collections.<String>emptyList());
}
return super.complete(buffer, cursor, candidates);
}
use of io.cdap.cdap.proto.id.ServiceId in project cdap by caskdata.
the class PreferencesClientTestRun method testProgramAPI.
@Test
public void testProgramAPI() throws Exception {
Map<String, String> propMap = Maps.newHashMap();
propMap.put("key", "instance");
File jarFile = createAppJarFile(AppReturnsArgs.class);
appClient.deploy(NamespaceId.DEFAULT, jarFile);
ApplicationId app = NamespaceId.DEFAULT.app(AppReturnsArgs.NAME);
ServiceId service = app.service(AppReturnsArgs.SERVICE);
try {
client.setInstancePreferences(propMap);
Map<String, String> setMap = Maps.newHashMap();
setMap.put("saved", "args");
programClient.setRuntimeArgs(service, setMap);
assertEquals(setMap, programClient.getRuntimeArgs(service));
propMap.put("run", "value");
propMap.put("logical.start.time", "1234567890000");
propMap.putAll(setMap);
programClient.start(service, false, propMap);
assertProgramRunning(programClient, service);
URL serviceURL = new URL(serviceClient.getServiceURL(service), AppReturnsArgs.ENDPOINT);
HttpResponse response = getServiceResponse(serviceURL);
assertEquals(HttpURLConnection.HTTP_OK, response.getResponseCode());
Map<String, String> responseMap = GSON.fromJson(response.getResponseBodyAsString(), STRING_MAP_TYPE);
assertEquals(propMap, responseMap);
programClient.stop(service);
assertProgramStopped(programClient, service);
assertProgramRuns(programClient, service, ProgramRunStatus.KILLED, 1, 10);
long minStartTime = System.currentTimeMillis();
client.deleteInstancePreferences();
programClient.start(service);
assertProgramRunning(programClient, service);
propMap.remove("key");
propMap.remove("run");
propMap.remove("logical.start.time");
serviceURL = new URL(serviceClient.getServiceURL(service), AppReturnsArgs.ENDPOINT);
response = getServiceResponse(serviceURL);
responseMap = GSON.fromJson(response.getResponseBodyAsString(), STRING_MAP_TYPE);
long actualStartTime = Long.parseLong(responseMap.remove("logical.start.time"));
Assert.assertTrue(actualStartTime >= minStartTime);
assertEquals(propMap, responseMap);
programClient.stop(service);
assertProgramStopped(programClient, service);
assertProgramRuns(programClient, service, ProgramRunStatus.KILLED, 2, 10);
propMap.clear();
minStartTime = System.currentTimeMillis();
programClient.setRuntimeArgs(service, propMap);
programClient.start(service);
assertProgramRunning(programClient, service);
serviceURL = new URL(serviceClient.getServiceURL(service), AppReturnsArgs.ENDPOINT);
response = getServiceResponse(serviceURL);
assertEquals(HttpURLConnection.HTTP_OK, response.getResponseCode());
responseMap = GSON.fromJson(response.getResponseBodyAsString(), STRING_MAP_TYPE);
actualStartTime = Long.parseLong(responseMap.remove("logical.start.time"));
Assert.assertTrue(actualStartTime >= minStartTime);
assertEquals(propMap, responseMap);
} finally {
programClient.stop(service);
assertProgramStopped(programClient, service);
appClient.delete(app);
}
}
use of io.cdap.cdap.proto.id.ServiceId in project cdap by caskdata.
the class QueryClientTest method testAll.
@Test
public void testAll() throws Exception {
NamespaceId namespace = new NamespaceId("queryClientTestNamespace");
NamespaceId otherNamespace = new NamespaceId("queryClientOtherNamespace");
namespaceClient.create(new NamespaceMeta.Builder().setName(namespace).build());
ApplicationId app = namespace.app(FakeApp.NAME);
ServiceId service = app.service(DatasetWriterService.NAME);
DatasetId dataset = namespace.dataset(FakeApp.DS_NAME);
appClient.deploy(namespace, createAppJarFile(FakeApp.class));
try {
programClient.start(service);
assertProgramRunning(programClient, service);
// Write some data through the service
Map<String, String> data = new HashMap<>();
data.put("bob", "123");
data.put("joe", "321");
URL writeURL = new URL(serviceClient.getServiceURL(service), "write");
HttpResponse response = HttpRequests.execute(HttpRequest.post(writeURL).withBody(new Gson().toJson(data)).build(), new DefaultHttpRequestConfig(false));
Assert.assertEquals(200, response.getResponseCode());
executeBasicQuery(namespace, FakeApp.DS_NAME);
exploreClient.disableExploreDataset(dataset).get();
try {
queryClient.execute(namespace, "select * from " + FakeApp.DS_NAME).get();
Assert.fail("Explore Query should have thrown an ExecutionException since explore is disabled");
} catch (ExecutionException e) {
// ignored
}
exploreClient.enableExploreDataset(dataset).get();
executeBasicQuery(namespace, FakeApp.DS_NAME);
try {
queryClient.execute(otherNamespace, "show tables").get();
Assert.fail("Explore Query should have thrown an ExecutionException since the database should not exist");
} catch (ExecutionException e) {
// expected
}
} finally {
programClient.stop(service);
assertProgramStopped(programClient, service);
try {
appClient.delete(app);
} catch (Exception e) {
LOG.error("Error deleting app {} during test cleanup.", e);
}
}
}
Aggregations