Package co.cask.cdap.app

Examples of co.cask.cdap.app.ApplicationSpecification


        String appId = requestedObj.getAppId();
        String programTypeStr = requestedObj.getProgramType();
        String programId = requestedObj.getProgramId();
        // these values will be overwritten later
        int requested, provisioned;
        ApplicationSpecification spec = store.getApplication(Id.Application.from(accountId, appId));
        if (spec == null) {
          addCodeError(requestedObj, HttpResponseStatus.NOT_FOUND.getCode(), "App: " + appId + " not found");
          continue;
        }
        ProgramType programType = ProgramType.valueOfPrettyName(programTypeStr);
        String runnableId;
        if (programType == ProgramType.PROCEDURE) {
          // the "runnable" for procedures has the same id as the procedure name
          runnableId = programId;
          if (spec.getProcedures().containsKey(programId)) {
            requested = store.getProcedureInstances(Id.Program.from(accountId, appId, programId));
          } else {
            addCodeError(requestedObj, HttpResponseStatus.NOT_FOUND.getCode(),
                         "Procedure: " + programId + " not found");
            continue;
          }
        } else {
          // cant get instances for things that are not flows, services, or procedures
          if (programType != ProgramType.FLOW && programType != ProgramType.SERVICE) {
            addCodeError(requestedObj, HttpResponseStatus.BAD_REQUEST.getCode(),
                         "Program type: " + programType + " is not a valid program type to get instances");
            continue;
          }
          // services and flows must have runnable id
          if (requestedObj.getRunnableId() == null) {
            responder.sendJson(HttpResponseStatus.BAD_REQUEST, "Must provide a string runnableId for flows/services");
            return;
          }
          runnableId = requestedObj.getRunnableId();
          if (programType == ProgramType.FLOW) {
            FlowSpecification flowSpec = spec.getFlows().get(programId);
            if (flowSpec != null) {
              Map<String, FlowletDefinition> flowletSpecs = flowSpec.getFlowlets();
              if (flowletSpecs != null && flowletSpecs.containsKey(runnableId)) {
                requested = flowletSpecs.get(runnableId).getInstances();
              } else {
                addCodeError(requestedObj, HttpResponseStatus.NOT_FOUND.getCode(),
                             "Flowlet: " + runnableId + " not found");
                continue;
              }
            } else {
              addCodeError(requestedObj, HttpResponseStatus.NOT_FOUND.getCode(), "Flow: " + programId + " not found");
              continue;
            }
          } else {
            // Services
            ServiceSpecification serviceSpec = spec.getServices().get(programId);
            if (serviceSpec != null) {
              Map<String, RuntimeSpecification> runtimeSpecs = serviceSpec.getRunnables();
              if (runtimeSpecs != null && runtimeSpecs.containsKey(runnableId)) {
                requested = runtimeSpecs.get(runnableId).getResourceSpecification().getInstances();
              } else {
View Full Code Here


        }
      });

      ApplicationWithPrograms applicationWithPrograms =
        manager.deploy(id, appId, archiveLocation).get();
      ApplicationSpecification specification = applicationWithPrograms.getAppSpecLoc().getSpecification();
      setupSchedules(accountId, specification);
    } catch (Throwable e) {
      LOG.warn(e.getMessage(), e);
      throw new Exception(e.getMessage());
    }
View Full Code Here

    if (appRunning) {
      return AppFabricServiceStatus.PROGRAM_STILL_RUNNING;
    }

    ApplicationSpecification spec = store.getApplication(appId);
    if (spec == null) {
      return AppFabricServiceStatus.PROGRAM_NOT_FOUND;
    }

    //Delete the schedules
    for (WorkflowSpecification workflowSpec : spec.getWorkflows().values()) {
      Id.Program workflowProgramId = Id.Program.from(appId, workflowSpec.getName());
      List<String> schedules = scheduler.getScheduleIds(workflowProgramId, ProgramType.WORKFLOW);
      if (!schedules.isEmpty()) {
        scheduler.deleteSchedules(workflowProgramId, ProgramType.WORKFLOW, schedules);
      }
    }

    deleteMetrics(identifier.getAccountId(), identifier.getApplicationId());

    // Delete all streams and queues state of each flow
    // TODO: This should be unified with the DeletedProgramHandlerStage
    for (FlowSpecification flowSpecification : spec.getFlows().values()) {
      Id.Program flowProgramId = Id.Program.from(appId, flowSpecification.getName());

      // Collects stream name to all group ids consuming that stream
      Multimap<String, Long> streamGroups = HashMultimap.create();
      for (FlowletConnection connection : flowSpecification.getConnections()) {
View Full Code Here

  private void deleteMetrics(String accountId, String applicationId) throws IOException, OperationException {
    Collection<ApplicationSpecification> applications = Lists.newArrayList();
    if (applicationId == null) {
      applications = this.store.getAllApplications(new Id.Account(accountId));
    } else {
      ApplicationSpecification spec = this.store.getApplication
        (new Id.Application(new Id.Account(accountId), applicationId));
      applications.add(spec);
    }
    Iterable<Discoverable> discoverables = this.discoveryServiceClient.discover(Constants.Service.METRICS);
    Discoverable discoverable = new TimeLimitEndpointStrategy(new RandomEndpointStrategy(discoverables),
View Full Code Here

   *
   * @param appId        applicationId.
   * @throws IOException if there are errors with location IO
   */
  private void deleteProgramLocations(Id.Application appId) throws IOException, OperationException {
    ApplicationSpecification specification = store.getApplication(appId);

    Iterable<ProgramSpecification> programSpecs = Iterables.concat(specification.getFlows().values(),
                                                                   specification.getMapReduce().values(),
                                                                   specification.getProcedures().values(),
                                                                   specification.getWorkflows().values());

    for (ProgramSpecification spec : programSpecs) {
      ProgramType type = ProgramTypes.fromSpecification(spec);
      Id.Program programId = Id.Program.from(appId, spec.getName());
      try {
View Full Code Here

  }

  private String getProgramSpecification(Id.Program id, ProgramType type)
    throws Exception {

    ApplicationSpecification appSpec;
    try {
      appSpec = store.getApplication(id.getApplication());
      if (appSpec == null) {
        return "";
      }
      String runnableId = id.getId();
      if (type == ProgramType.FLOW && appSpec.getFlows().containsKey(runnableId)) {
        return GSON.toJson(appSpec.getFlows().get(id.getId()));
      } else if (type == ProgramType.PROCEDURE && appSpec.getProcedures().containsKey(runnableId)) {
        return GSON.toJson(appSpec.getProcedures().get(id.getId()));
      } else if (type == ProgramType.MAPREDUCE && appSpec.getMapReduce().containsKey(runnableId)) {
        return GSON.toJson(appSpec.getMapReduce().get(id.getId()));
      } else if (type == ProgramType.SPARK && appSpec.getSpark().containsKey(runnableId)) {
        return GSON.toJson(appSpec.getSpark().get(id.getId()));
      } else if (type == ProgramType.WORKFLOW && appSpec.getWorkflows().containsKey(runnableId)) {
        return GSON.toJson(appSpec.getWorkflows().get(id.getId()));
      } else if (type == ProgramType.SERVICE && appSpec.getServices().containsKey(runnableId)) {
        return GSON.toJson(appSpec.getServices().get(id.getId()));
      }
    } catch (Throwable throwable) {
      LOG.warn(throwable.getMessage(), throwable);
      throw new Exception(throwable.getMessage());
    }
View Full Code Here

  @Override
  protected ProgramController launch(Program program, ProgramOptions options,
                                     File hConfFile, File cConfFile, ApplicationLauncher launcher) {
    // Extract and verify parameters
    ApplicationSpecification appSpec = program.getSpecification();
    Preconditions.checkNotNull(appSpec, "Missing application specification.");

    ProgramType processorType = program.getType();
    Preconditions.checkNotNull(processorType, "Missing processor type.");
    Preconditions.checkArgument(processorType == ProgramType.WEBAPP, "Only WEBAPP process type is supported.");
View Full Code Here

      List<ApplicationRecord> result = Lists.newArrayList();
      List<ApplicationSpecification> specList;
      if (appid == null) {
        specList = new ArrayList<ApplicationSpecification>(store.getAllApplications(accId));
      } else {
        ApplicationSpecification appSpec = store.getApplication(new Id.Application(accId, appid));
        if (appSpec == null) {
          responder.sendStatus(HttpResponseStatus.NOT_FOUND);
          return;
        }
        specList = Collections.singletonList(store.getApplication(new Id.Application(accId, appid)));
View Full Code Here

      responder.sendStatus(HttpResponseStatus.INTERNAL_SERVER_ERROR);
    }
  }

  private String listProgramsByApp(Id.Application appId, ProgramType type) throws Exception {
    ApplicationSpecification appSpec;
    try {
      appSpec = store.getApplication(appId);
      if (appSpec == null) {
        return "";
      } else {
View Full Code Here

  }

  private String listDataEntitiesByApp(Id.Program programId, Data type) throws Exception {
    try {
      Id.Account account = new Id.Account(programId.getAccountId());
      ApplicationSpecification appSpec = store.getApplication(new Id.Application(
        account, programId.getApplicationId()));
      if (type == Data.DATASET) {
        Set<String> dataSetsUsed = dataSetsUsedBy(appSpec);
        List<DatasetRecord> result = Lists.newArrayListWithExpectedSize(dataSetsUsed.size());
        for (String dsName : dataSetsUsed) {
View Full Code Here

TOP

Related Classes of co.cask.cdap.app.ApplicationSpecification

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.