private void deleteMetrics(NamespaceId namespaceId) { long endTs = System.currentTimeMillis() / 1000; Map<String, String> tags = new LinkedHashMap<>(); tags.put(Constants.Metrics.Tag.NAMESPACE, namespaceId.getNamespace()); MetricDeleteQuery deleteQuery = new MetricDeleteQuery(0, endTs, Collections.emptySet(), tags, new ArrayList<>(tags.keySet())); metricStore.delete(deleteQuery); } }
@Override public void removeAll(NamespaceId id) { LOG.trace("Removing all applications of namespace with id: {}", id.getNamespace()); Transactionals.execute(transactional, context -> { AppMetadataStore metaStore = getAppMetadataStore(context); metaStore.deleteApplications(id.getNamespace()); metaStore.deleteProgramHistory(id.getNamespace()); }); }
@Override public void removeAllApplications(NamespaceId id) { LOG.trace("Removing all applications of namespace with id: {}", id.getNamespace()); Transactionals.execute(transactional, context -> { AppMetadataStore metaStore = getAppMetadataStore(context); metaStore.deleteApplications(id.getNamespace()); metaStore.deleteProgramHistory(id.getNamespace()); }); }
private DatasetId deserializeDatasetId(JsonObject id) { NamespaceId namespace = deserializeNamespace(id); String instanceId = id.get("dataset").getAsString(); return new DatasetId(namespace.getNamespace(), instanceId); }
@Override public URI getURI() { return URI.create(String.format("%s://%s%s:%d/%s", super.isSSLEnabled() ? "https" : "http", username == null ? "" : username + "@", super.getHostname(), super.getPort(), namespace.getNamespace())); } }
public void removeNamespace(NamespaceId namespace) throws ExploreException, SQLException { if (!exploreEnabled) { return; } ListenableFuture<ExploreExecutionResult> futureSuccess = exploreClient.removeNamespace(namespace); handleExploreFuture(futureSuccess, "remove", "namespace", namespace.getNamespace()); }
@Override public void perform(Arguments arguments, PrintStream output) throws Exception { NamespaceId namespace = new NamespaceId(arguments.get(ArgumentName.NAMESPACE_NAME.toString())); // Check if namespace exists; throws exception if namespace doesn't exist. namespaceClient.get(namespace); cliConfig.setNamespace(namespace); output.printf("Now using namespace '%s'\n", namespace.getNamespace()); }
@Override public void perform(Arguments arguments, PrintStream printStream) throws Exception { String[] programIdParts = arguments.get(elementType.getArgumentName().toString()).split("\\."); if (programIdParts.length < 2) { throw new CommandInputError(this); } ProgramRunId programRunId = new ProgramRunId(cliConfig.getCurrentNamespace().getNamespace(), programIdParts[0], ProgramType.WORKFLOW, programIdParts[1], arguments.get(ArgumentName.RUN_ID.toString())); workflowClient.deleteWorkflowLocalDatasets(programRunId); printStream.printf("Successfully deleted local datasets associated with the workflow run."); }
@Override public Trigger onProgramStatus(String application, ProgramType programType, String program, ProgramStatus... programStatuses) { return new ProgramStatusTrigger(new ProgramId(namespaceId.getNamespace(), application, co.cask.cdap.proto.ProgramType.valueOf(programType.name()), program), programStatuses); }
public void deleteAllApplications(NamespaceId namespaceId) throws Exception { HttpRequest request = new DefaultHttpRequest( HttpVersion.HTTP_1_1, HttpMethod.DELETE, String.format("%s/apps", getNamespacePath(namespaceId.getNamespace())) ); request.headers().set(Constants.Gateway.API_KEY, "api-key-example"); MockResponder mockResponder = new MockResponder(); appLifecycleHttpHandler.deleteAllApps(request, mockResponder, namespaceId.getNamespace()); verifyResponse(HttpResponseStatus.OK, mockResponder.getStatus(), "Deleting all apps failed"); }
@Override protected Injector doInit(TwillContext context) { CConfiguration cConf = getCConfiguration(); cConf.set(Constants.MessagingSystem.HTTP_SERVER_BIND_ADDRESS, context.getHost().getHostName()); cConf.setInt(Constants.MessagingSystem.CONTAINER_INSTANCE_ID, context.getInstanceId()); injector = createInjector(cConf, getConfiguration()); injector.getInstance(LogAppenderInitializer.class).initialize(); LoggingContextAccessor.setLoggingContext(new ServiceLoggingContext(NamespaceId.SYSTEM.getNamespace(), Constants.Logging.COMPONENT_NAME, Constants.Service.MESSAGING_SERVICE)); return injector; }
@Override protected String getTableNameAsString(TableId tableId) { Preconditions.checkArgument(tableId != null, "TableId should not be null."); String tablePrefix = cConf.get(Constants.Dataset.TABLE_PREFIX); if (NamespaceId.DEFAULT.getNamespace().equals(tableId.getNamespace())) { return HTableNameConverter.toHBaseTableName(tablePrefix, tableId); } return Joiner.on(':').join(tableId.getNamespace(), HTableNameConverter.toHBaseTableName(tablePrefix, tableId)); }
private void testTaskMetric(String runId, boolean doesExist) throws Exception { List<TagValue> tags = new ArrayList<>(); tags.add(new TagValue(Constants.Metrics.Tag.NAMESPACE, NamespaceId.DEFAULT.getNamespace())); tags.add(new TagValue(Constants.Metrics.Tag.APP, DatasetWithMRApp.class.getSimpleName())); tags.add(new TagValue(Constants.Metrics.Tag.MAPREDUCE, DatasetWithMRApp.MAPREDUCE_PROGRAM)); tags.add(new TagValue(Constants.Metrics.Tag.RUN_ID, runId)); Collection<String> metricNames = getMetricsManager().searchMetricNames(new MetricSearchQuery(0, Integer.MAX_VALUE, Integer.MAX_VALUE, tags)); // we disabled task level metrics; this should return empty list Assert.assertEquals(doesExist, metricNames.contains("user.test.metric")); }
protected List<BatchProgramHistory> getProgramRuns(NamespaceId namespace, List<ProgramId> programs) throws Exception { List<BatchProgram> request = programs.stream() .map(program -> new BatchProgram(program.getApplication(), program.getType(), program.getProgram())) .collect(Collectors.toList()); HttpResponse response = doPost(getVersionedAPIPath("runs", namespace.getNamespace()), GSON.toJson(request)); Assert.assertEquals(200, response.getResponseCode()); return GSON.fromJson(response.getResponseBodyAsString(), BATCH_PROGRAM_RUNS_TYPE); }
private static void verifyAlreadyExist(NamespaceMeta namespaceMeta, NamespaceId existingNamespace) throws Exception { try { namespaceAdmin.create(namespaceMeta); Assert.fail(String.format("Namespace '%s' should not have been created", namespaceMeta.getName())); } catch (BadRequestException e) { Assert.assertTrue(e.getMessage().contains(existingNamespace.getNamespace())); } }
private static void verifyNotFound(NamespaceId namespaceId) throws Exception { try { namespaceAdmin.get(namespaceId); Assert.fail(String.format("Namespace '%s' should not be found since it was just deleted", namespaceId.getNamespace())); } catch (NamespaceNotFoundException e) { Assert.assertEquals(namespaceId, e.getId()); } } }
private ApplicationManager deploy(NamespaceId namespaceId, Class<? extends Application> appClass) throws Exception { ArtifactId artifactId = new ArtifactId(namespaceId.getNamespace(), appClass.getSimpleName(), "1.0-SNAPSHOT"); addArtifact(artifactId, ARTIFACTS.get(appClass)); AppRequest<?> appRequest = new AppRequest<>(new ArtifactSummary(artifactId.getArtifact(), artifactId.getVersion()), null); return deployApplication(namespaceId.app(appClass.getSimpleName()), appRequest); }
/** * Deploys an {@link Application} using the given artifact jar with an optional config object. */ protected static <T> ApplicationManager deployWithArtifact(NamespaceId namespaceId, Class<? extends Application> appClass, File artifactJar, @Nullable T config) throws Exception { ArtifactId artifactId = new ArtifactId(namespaceId.getNamespace(), appClass.getSimpleName(), "1.0-SNAPSHOT"); addArtifact(artifactId, artifactJar); AppRequest<T> appRequest = new AppRequest<>(new ArtifactSummary(artifactId.getArtifact(), artifactId.getVersion()), config); return deployApplication(namespaceId.app(appClass.getSimpleName()), appRequest); }
private void testDeployAppWithOwner() throws Exception { NamespaceId namespaceId = new NamespaceId("appImpersonation"); NamespaceMeta nsMeta = new NamespaceMeta.Builder().setName(namespaceId.getNamespace()).build(); // grant ALICE admin on namespace and create namespace grantAndAssertSuccess(namespaceId, ALICE, EnumSet.of(Action.ADMIN)); cleanUpEntities.add(namespaceId); getNamespaceAdmin().create(nsMeta); // deploy dummy app with app impersonation deployDummyAppWithImpersonation(nsMeta, BOB.getName()); }
@Test public void testNamespaceAvailableAtRuntime() throws Exception { ApplicationManager applicationManager = deployApplication(testSpace, AppUsingNamespace.class); ServiceManager serviceManager = applicationManager.getServiceManager(AppUsingNamespace.SERVICE_NAME); serviceManager.start(); serviceManager.waitForRun(ProgramRunStatus.RUNNING, 10, TimeUnit.SECONDS); URL serviceURL = serviceManager.getServiceURL(10, TimeUnit.SECONDS); Assert.assertEquals(testSpace.getNamespace(), callServiceGet(serviceURL, "ns")); serviceManager.stop(); serviceManager.waitForStopped(10, TimeUnit.SECONDS); }