/** * Since this is often created through gson deserialization, check that all the fields are present and valid. * * @throws IllegalArgumentException if there is a field that is null or empty or invalid. */ public void validate() throws IllegalArgumentException { if (appId == null || appId.isEmpty()) { throw new IllegalArgumentException("'appId' must be specified."); } if (programType == null) { throw new IllegalArgumentException("'programType' must be one of " + Arrays.toString(ProgramType.values())); } if (programId == null || programId.isEmpty()) { throw new IllegalArgumentException("'programId' must be specified."); } }
/** * Since this is often created through gson deserialization, check that all the fields are present and valid. * * @throws IllegalArgumentException if there is a field that is null or empty or invalid. */ public void validate() throws IllegalArgumentException { if (appId == null || appId.isEmpty()) { throw new IllegalArgumentException("'appId' must be specified."); } if (programType == null) { throw new IllegalArgumentException("'programType' must be one of " + Arrays.toString(ProgramType.values())); } if (programId == null || programId.isEmpty()) { throw new IllegalArgumentException("'programId' must be specified."); } }
public static ProgramType valueOfSchedulableType(SchedulableProgramType schedulableType) { for (ProgramType type : ProgramType.values()) { if (schedulableType.equals(type.parameters.getSchedulableType())) { return type; } } throw new IllegalArgumentException("No ProgramType found for SchedulableProgramType " + schedulableType); }
public static ProgramType valueOfSchedulableType(SchedulableProgramType schedulableType) { for (ProgramType type : ProgramType.values()) { if (schedulableType.equals(type.parameters.getSchedulableType())) { return type; } } throw new IllegalArgumentException("No ProgramType found for SchedulableProgramType " + schedulableType); }
/** * Lists programs of a type belonging to an application. * * @param app the application * @return Map of {@link ProgramType} to list of {@link ProgramRecord}s * @throws ApplicationNotFoundException if the application with the given ID was not found * @throws IOException if a network error occurred * @throws UnauthenticatedException if the request is not authorized successfully in the gateway server */ public Map<ProgramType, List<ProgramRecord>> listProgramsByType(ApplicationId app) throws ApplicationNotFoundException, IOException, UnauthenticatedException, UnauthorizedException { Map<ProgramType, List<ProgramRecord>> result = Maps.newHashMap(); for (ProgramType type : ProgramType.values()) { result.put(type, Lists.<ProgramRecord>newArrayList()); } for (ProgramRecord program : listPrograms(app)) { result.get(program.getType()).add(program); } return result; }
/** * Lists all programs. * * @return list of {@link ProgramRecord}s * @throws IOException if a network error occurred * @throws UnauthenticatedException if the request is not authorized successfully in the gateway server */ public Map<ProgramType, List<ProgramRecord>> listAllPrograms(NamespaceId namespace) throws IOException, UnauthenticatedException, UnauthorizedException { ImmutableMap.Builder<ProgramType, List<ProgramRecord>> allPrograms = ImmutableMap.builder(); for (ProgramType programType : ProgramType.values()) { if (programType.isListable()) { List<ProgramRecord> programRecords = Lists.newArrayList(); programRecords.addAll(listAllPrograms(namespace, programType)); allPrograms.put(programType, programRecords); } } return allPrograms.build(); }
private void stopAllPrograms() { LOG.info("Stopping all running programs."); List<ListenableFuture<ProgramController>> futures = Lists.newLinkedList(); for (ProgramType type : ProgramType.values()) { for (Map.Entry<RunId, RuntimeInfo> entry : list(type).entrySet()) { RuntimeInfo runtimeInfo = entry.getValue(); if (isRunning(runtimeInfo.getProgramId())) { futures.add(runtimeInfo.getController().stop()); } } } // unchecked because we cannot do much if it fails. We will still shutdown the standalone CDAP instance. try { Futures.successfulAsList(futures).get(60, TimeUnit.SECONDS); LOG.info("All programs have been stopped."); } catch (ExecutionException e) { // note this should not happen because we wait on a successfulAsList LOG.warn("Got exception while waiting for all programs to stop", e.getCause()); } catch (InterruptedException e) { LOG.warn("Got interrupted exception while waiting for all programs to stop", e); Thread.currentThread().interrupt(); } catch (TimeoutException e) { // can't do much more than log it. We still want to exit. LOG.warn("Timeout while waiting for all programs to stop."); } } }
private void stopAllPrograms() { LOG.info("Stopping all running programs."); List<ListenableFuture<ProgramController>> futures = Lists.newLinkedList(); for (ProgramType type : ProgramType.values()) { for (Map.Entry<RunId, RuntimeInfo> entry : list(type).entrySet()) { RuntimeInfo runtimeInfo = entry.getValue(); if (isRunning(runtimeInfo.getProgramId())) { futures.add(runtimeInfo.getController().stop()); } } } // unchecked because we cannot do much if it fails. We will still shutdown the standalone CDAP instance. try { Futures.successfulAsList(futures).get(60, TimeUnit.SECONDS); LOG.info("All programs have been stopped."); } catch (ExecutionException e) { // note this should not happen because we wait on a successfulAsList LOG.warn("Got exception while waiting for all programs to stop", e.getCause()); } catch (InterruptedException e) { LOG.warn("Got interrupted exception while waiting for all programs to stop", e); Thread.currentThread().interrupt(); } catch (TimeoutException e) { // can't do much more than log it. We still want to exit. LOG.warn("Timeout while waiting for all programs to stop."); } } }
@Test public void testDuplicateWritesIgnored() throws Exception { DatasetId storeTable = NamespaceId.DEFAULT.dataset("duplicateWrites"); datasetFramework.addInstance(Table.class.getName(), storeTable, DatasetProperties.EMPTY); Table table = datasetFramework.getDataset(storeTable, Collections.emptyMap(), null); Assert.assertNotNull(table); AppMetadataStore store = new AppMetadataStore(table, cConf); TransactionExecutor txnl = txExecutorFactory.createExecutor(Collections.singleton(store)); ApplicationId application = NamespaceId.DEFAULT.app("app"); ProgramId program = application.program(ProgramType.values()[ProgramType.values().length - 1], "program"); ProgramRunId runId = program.run(RunIds.generate()); byte[] sourceId = new byte[] { 0 }; txnl.execute(() -> { assertSecondCallIsNull(() -> store.recordProgramProvisioning(runId, null, SINGLETON_PROFILE_MAP, sourceId, ARTIFACT_ID)); assertSecondCallIsNull(() -> store.recordProgramProvisioned(runId, 0, sourceId)); assertSecondCallIsNull(() -> store.recordProgramStart(runId, null, Collections.emptyMap(), sourceId)); assertSecondCallIsNull(() -> store.recordProgramRunning(runId, System.currentTimeMillis(), null, sourceId)); assertSecondCallIsNull(() -> store.recordProgramSuspend(runId, sourceId, System.currentTimeMillis())); assertSecondCallIsNull(() -> store.recordProgramRunning(runId, System.currentTimeMillis(), null, sourceId)); assertSecondCallIsNull(() -> store.recordProgramStop(runId, System.currentTimeMillis(), ProgramRunStatus.KILLED, null, sourceId)); assertSecondCallIsNull(() -> store.recordProgramDeprovisioning(runId, sourceId)); assertSecondCallIsNull(() -> store.recordProgramDeprovisioned(runId, System.currentTimeMillis(), sourceId)); }); }
ApplicationId application = NamespaceId.DEFAULT.app("app" + i); ArtifactId artifactId = application.getNamespaceId().artifact("testArtifact", "1.0").toApiArtifactId(); ProgramId program = application.program(ProgramType.values()[i % ProgramType.values().length], "program" + i); long startTime = (i + 1) * 10000;