@Override public List<?> makeRow(ProgramRecord object) { return Lists.newArrayList(object.getType().getCategoryName(), object.getApp(), object.getName(), object.getDescription()); } }).build();
@Override public Set<String> getSystemTagsToAdd() { return ImmutableSet.<String>builder() .add(programId.getType().getPrettyName()) .add(getMode()) .addAll(getWorkflowNodes()) .build(); }
public ProgramStatusTriggerBuilder(String programType, String programName, ProgramStatus... programStatuses) { this.programType = ProgramType.valueOf(programType); this.programName = programName; // User can not specify any program statuses, or specify null, which is an array of length 1 containing null if (programStatuses.length == 0 || (programStatuses.length == 1 && programStatuses[0] == null)) { throw new IllegalArgumentException("Must set a program state for the triggering program"); } this.programStatuses = EnumSet.of(programStatuses[0], programStatuses); }
/** * 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(); }
/** * Lists programs of a type belonging to an application. * * @param app the application * @param programType type of the programs to list * @return 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 List<ProgramRecord> listPrograms(ApplicationId app, ProgramType programType) throws ApplicationNotFoundException, IOException, UnauthenticatedException, UnauthorizedException { Preconditions.checkArgument(programType.isListable()); List<ProgramRecord> programs = Lists.newArrayList(); for (ProgramRecord program : listPrograms(app)) { if (programType.equals(program.getType())) { programs.add(program); } } return programs; }
public static boolean isUserService(String discoverableName) { for (ProgramType type : USER_SERVICE_TYPES) { if (discoverableName.startsWith(type.name().toLowerCase() + ".")) { return true; } } return false; }
/** * Parses the give program type into {@link ProgramType} object. * * @param programType the program type to parse. * * @throws BadRequestException if the given program type is not a valid {@link ProgramType}. */ private ProgramType getProgramType(String programType) throws BadRequestException { try { return ProgramType.valueOfCategoryName(programType); } catch (Exception e) { throw new BadRequestException(String.format("Invalid program type '%s'", programType), e); } } }
/** * 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."); } }
@Override public Map<RunId, RuntimeInfo> list(ProgramType type) { Map<RunId, RuntimeInfo> result = new HashMap<>(); Lock lock = runtimeInfosLock.readLock(); lock.lock(); try { result.putAll(runtimeInfos.row(type)); } finally { lock.unlock(); } // Add any missing RuntimeInfo from the remote twill runner if (remoteTwillRunnerService == null) { return Collections.unmodifiableMap(result); } for (TwillRunner.LiveInfo liveInfo : remoteTwillRunnerService.lookupLive()) { ProgramId programId = TwillAppNames.fromTwillAppName(liveInfo.getApplicationName(), false); if (programId == null || !programId.getType().equals(type)) { continue; } for (TwillController controller : liveInfo.getControllers()) { // For remote twill runner, the twill run id and cdap run id are the same RunId runId = controller.getRunId(); if (result.computeIfAbsent(runId, rid -> createRuntimeInfo(programId, runId, controller)) == null) { LOG.warn("Unable to create runtime info for program {} with run id {}", programId, runId); } } } return Collections.unmodifiableMap(result); }
for (ProgramType type : ProgramType.values()) { if (!ProgramType.CUSTOM_ACTION.equals(type)) { Assert.assertTrue(programLifecycleService.list(NamespaceId.DEFAULT, type).isEmpty()); Collections.singleton(Action.EXECUTE)); for (ProgramType type : ProgramType.values()) { if (!ProgramType.CUSTOM_ACTION.equals(type)) { Assert.assertFalse(programLifecycleService.list(NamespaceId.DEFAULT, type).isEmpty()); SecurityRequestContext.setUserId("bob");
public static boolean isUserService(String discoverableName) { for (ProgramType type : USER_SERVICE_TYPES) { if (discoverableName.startsWith(type.name().toLowerCase() + ".")) { return true; } } return false; }
/** * Parses the give program type into {@link ProgramType} object. * * @param programType the program type to parse. * * @throws BadRequestException if the given program type is not a valid {@link ProgramType}. */ private ProgramType getProgramType(String programType) throws BadRequestException { try { return ProgramType.valueOfCategoryName(programType); } catch (Exception e) { throw new BadRequestException(String.format("Invalid program type '%s'", programType), e); } } }
/** * 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."); } }
@Override public Map<RunId, RuntimeInfo> list(ProgramType type) { Map<RunId, RuntimeInfo> result = new HashMap<>(); Lock lock = runtimeInfosLock.readLock(); lock.lock(); try { result.putAll(runtimeInfos.row(type)); } finally { lock.unlock(); } // Add any missing RuntimeInfo from the remote twill runner if (remoteTwillRunnerService == null) { return Collections.unmodifiableMap(result); } for (TwillRunner.LiveInfo liveInfo : remoteTwillRunnerService.lookupLive()) { ProgramId programId = TwillAppNames.fromTwillAppName(liveInfo.getApplicationName(), false); if (programId == null || !programId.getType().equals(type)) { continue; } for (TwillController controller : liveInfo.getControllers()) { // For remote twill runner, the twill run id and cdap run id are the same RunId runId = controller.getRunId(); if (result.computeIfAbsent(runId, rid -> createRuntimeInfo(programId, runId, controller)) == null) { LOG.warn("Unable to create runtime info for program {} with run id {}", programId, runId); } } } return Collections.unmodifiableMap(result); }
public void stopProgram(String namespaceId, String appId, String appVersion, String programId, ProgramType type) throws Exception { MockResponder responder = new MockResponder(); String uri = String.format("%s/apps/%s/versions/%s/%s/%s/stop", getNamespacePath(namespaceId), appId, appVersion, type.getCategoryName(), programId); FullHttpRequest request = new DefaultFullHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.POST, uri); HttpUtil.setContentLength(request, request.content().readableBytes()); programLifecycleHttpHandler.performAction(request, responder, namespaceId, appId, appVersion, type.getCategoryName(), programId, "stop"); verifyResponse(HttpResponseStatus.OK, responder.getStatus(), "Stop " + type + " failed"); }
@Override public Set<String> getSystemTagsToAdd() { return ImmutableSet.<String>builder() .add(programId.getType().getPrettyName()) .add(getMode()) .addAll(getWorkflowNodes()) .build(); }
public ProgramStatusTriggerBuilder(String programType, String programName, ProgramStatus... programStatuses) { this.programType = ProgramType.valueOf(programType); this.programName = programName; // User can not specify any program statuses, or specify null, which is an array of length 1 containing null if (programStatuses.length == 0 || (programStatuses.length == 1 && programStatuses[0] == null)) { throw new IllegalArgumentException("Must set a program state for the triggering program"); } this.programStatuses = EnumSet.of(programStatuses[0], programStatuses); }
public static String getName(String namespaceId, String appId, ProgramType programType, String programName) { if (!USER_SERVICE_TYPES.contains(programType)) { throw new IllegalArgumentException("Program type should be one of " + USER_SERVICE_TYPES); } return String.format("%s.%s.%s.%s", programType.name().toLowerCase(), namespaceId, appId, programName); }
/** * Parses the give program type into {@link ProgramType} object. * * @param programType the program type to parse. * * @throws BadRequestException if the given program type is not a valid {@link ProgramType}. */ private ProgramType getProgramType(String programType) throws BadRequestException { try { return ProgramType.valueOfCategoryName(programType); } catch (Exception e) { throw new BadRequestException(String.format("Invalid program type '%s'", programType), e); } } }