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 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()); }
private DatasetId getMappedDatasetInstance(DatasetId datasetInstanceId) { if (datasetNameMapping.containsKey(datasetInstanceId.getEntityName())) { return datasetInstanceId.getParent().dataset(datasetNameMapping.get(datasetInstanceId.getEntityName())); } return datasetInstanceId; } }
private String toCDAPManagedHBaseNamespace(NamespaceId namespace) { // Handle backward compatibility to not add the prefix for default namespace // TODO: CDAP-1601 - Conditional should be removed when we have a way to upgrade user datasets return NamespaceId.DEFAULT.getEntityName().equals(namespace.getNamespace()) ? namespace.getNamespace() : tablePrefix + "_" + namespace.getNamespace(); }
@SuppressWarnings("unused") public static NamespaceId fromIdParts(Iterable<String> idString) { Iterator<String> iterator = idString.iterator(); return new NamespaceId(nextAndEnd(iterator, "namespace")); }
private ProgramId getId() { ProgramType programType; try { programType = ProgramType.valueOf(type.toUpperCase()); } catch (IllegalArgumentException e) { throw new IllegalArgumentException(String.format("Invalid program type '%s': %s", type, e.getMessage()), e); } NamespaceId namespaceId = new NamespaceId(namespace); return namespaceId.app(application).program(programType, name); }
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); }
@Test public void testDoesNotExist() { assertDoesNotExist(new InstanceId(DOES_NOT_EXIST)); assertDoesNotExist(new NamespaceId(DOES_NOT_EXIST)); assertDoesNotExist(NamespaceId.DEFAULT.artifact(DOES_NOT_EXIST, "1.0")); ApplicationId app = NamespaceId.DEFAULT.app(AllProgramsApp.NAME); assertDoesNotExist(NamespaceId.DEFAULT.app(DOES_NOT_EXIST)); assertDoesNotExist(app.mr(DOES_NOT_EXIST)); assertDoesNotExist(NamespaceId.DEFAULT.dataset(DOES_NOT_EXIST)); }
/** * Return which entity scope this profile is in * * @return entity scope the profile is in */ public EntityScope getScope() { return getNamespaceId().equals(NamespaceId.SYSTEM) ? EntityScope.SYSTEM : EntityScope.USER; }
/** * @return the namespace to be used by default for test cases. */ private static NamespaceId configureTestNamespace() { String testNamespace = System.getProperty("test.namespace"); return testNamespace != null ? new NamespaceId(testNamespace) : NamespaceId.DEFAULT; }
protected AbstractStreamFileConsumerFactory(CConfiguration cConf, StreamAdmin streamAdmin, StreamConsumerStateStoreFactory stateStoreFactory) { this.cConf = cConf; this.streamAdmin = streamAdmin; this.stateStoreFactory = stateStoreFactory; this.tablePrefix = String.format("%s.%s", NamespaceId.SYSTEM.getEntityName(), QueueConstants.QueueType.STREAM.toString()); }
@PUT @Path("/topics/{topic}") public void createTopic(FullHttpRequest request, HttpResponder responder, @PathParam("namespace") String namespace, @PathParam("topic") String topic) throws Exception { TopicId topicId = new NamespaceId(namespace).topic(topic); messagingService.createTopic(new TopicMetadata(topicId, decodeTopicProperties(request.content()))); responder.sendStatus(HttpResponseStatus.OK); }
@GET @Path("/data/types/{name}") public void getTypeInfo(HttpRequest request, HttpResponder responder, @PathParam("namespace-id") String namespaceId, @PathParam("name") String name) throws Exception { responder.sendJson(HttpResponseStatus.OK, GSON.toJson(typeService.getType(new NamespaceId(namespaceId).datasetType(name)))); } }
@GET @Path("/routeconfig") public void getRouteConfig(HttpRequest request, HttpResponder responder, @PathParam("namespace-id") String namespaceId, @PathParam("app-id") String appId, @PathParam("service-id") String serviceId) throws Exception { ProgramId programId = Ids.namespace(namespaceId).app(appId).service(serviceId); RouteConfig routeConfig = routeStore.fetch(programId); responder.sendJson(HttpResponseStatus.OK, GSON.toJson(routeConfig.getRoutes())); }
@Test @SuppressWarnings("unchecked") public void testExists() throws NotFoundException { existenceVerifier.ensureExists(new InstanceId(EXISTS)); existenceVerifier.ensureExists(NAMESPACE); existenceVerifier.ensureExists(ARTIFACT); ApplicationId app = NAMESPACE.app(AllProgramsApp.NAME); existenceVerifier.ensureExists(app); existenceVerifier.ensureExists(app.mr(AllProgramsApp.NoOpMR.NAME)); existenceVerifier.ensureExists(NAMESPACE.dataset(AllProgramsApp.DATASET_NAME)); }
@BeforeClass public static void init() throws DatasetManagementException, IOException { dsFramework = dsFrameworkUtil.getFramework(); dsFramework.addModule(NAMESPACE.datasetModule("testDataset"), new TestDatasetModule()); dsFramework.addModule(NAMESPACE2.datasetModule("testDataset"), new TestDatasetModule()); txClient = new InMemoryTxSystemClient(dsFrameworkUtil.getTxManager()); dsFrameworkUtil.createInstance("testDataset", NAMESPACE.dataset("a"), DatasetProperties.EMPTY); dsFrameworkUtil.createInstance("testDataset", NAMESPACE.dataset("b"), DatasetProperties.EMPTY); dsFrameworkUtil.createInstance("testDataset", NAMESPACE.dataset("c"), DatasetProperties.EMPTY); dsFrameworkUtil.createInstance("testDataset", NAMESPACE2.dataset("a2"), DatasetProperties.EMPTY); dsFrameworkUtil.createInstance("testDataset", NAMESPACE2.dataset("c2"), DatasetProperties.EMPTY); }
@Override public EntityId apply(DatasetTypeMeta input) { return namespaceId.datasetType(input.getName()); } }, null);
@Test public void testAppFromArtifact() throws Exception { ArtifactId artifactId = NamespaceId.DEFAULT.artifact("cfg-app", "1.0.0-SNAPSHOT"); addAppArtifact(artifactId, ConfigTestApp.class); ApplicationId appId = NamespaceId.DEFAULT.app("AppFromArtifact"); AppRequest<ConfigTestApp.ConfigClass> createRequest = new AppRequest<>( new ArtifactSummary(artifactId.getArtifact(), artifactId.getVersion()), new ConfigTestApp.ConfigClass("testStream", "testDataset") ); ApplicationManager appManager = deployApplication(appId, createRequest); testAppConfig(appId.getApplication(), appManager, createRequest.getConfig()); }
@GET @Path("/previews/{preview-id}/status") public void getStatus(HttpRequest request, HttpResponder responder, @PathParam("namespace-id") String namespaceId, @PathParam("preview-id") String previewId) throws Exception { NamespaceId namespace = new NamespaceId(namespaceId); ApplicationId application = namespace.app(previewId); responder.sendJson(HttpResponseStatus.OK, GSON.toJson(previewManager.getRunner(application).getStatus())); }
/** * 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); }