/*
(non-Javadoc)

@see
com.twitter.hraven.JobDescFactoryBase#getAppIdFromJobName(java.lang.String)
554089
@Override
  String getAppIdFromJobName(String jobName) {
    if (jobName == null) {
      return null;
    }

    Matcher matcher = scheduledJobnamePattern.matcher(jobName);

    // TODO: Externalize patterns to make them configurable
    if (matcher.matches()) {
      jobName = SCHEDULED_PREFIX + matcher.group(1);
    }

    return jobName;
  }
1056183
public ApplicationField getField(int appId, String externalId) {
		return getResourceFactory().getApiResource(
				"/app/" + appId + "/field/" + externalId).get(
				ApplicationField.class);
	}
425196
public com.google.protobuf.ByteString
      getAppNameSetterBytes() {
    java.lang.Object ref = appNameSetter_;
    if (ref instanceof java.lang.String) {
      com.google.protobuf.ByteString b = 
          com.google.protobuf.ByteString.copyFromUtf8(
              (java.lang.String) ref);
      appNameSetter_ = b;
      return b;
    } else {
      return (com.google.protobuf.ByteString) ref;
    }
  }
129302
static String getFullyQualifiedJobName(DagNode<JobExecutionPlan> dagNode) {
    Config jobConfig = dagNode.getValue().getJobSpec().getConfig();

    String flowGroup = ConfigUtils.getString(jobConfig, ConfigurationKeys.FLOW_GROUP_KEY, "");
    String flowName = ConfigUtils.getString(jobConfig, ConfigurationKeys.FLOW_NAME_KEY, "");
    Long flowExecutionId = ConfigUtils.getLong(jobConfig, ConfigurationKeys.FLOW_EXECUTION_ID_KEY, 0L);
    String jobName = ConfigUtils.getString(jobConfig, ConfigurationKeys.JOB_NAME_KEY, "");

    return "(flowGroup: " + flowGroup + ", flowName: " + flowName + ", flowExecutionId: " + flowExecutionId + ", jobName: " + jobName + ")";
  }
128889
public static String getLabel(ComponentJob job, boolean includeDescriptorName, boolean includeInputColumnNames,
            boolean includeRequirements) {
        final String jobName = job.getName();
        final StringBuilder label = new StringBuilder();
        if (Strings.isNullOrEmpty(jobName)) {
            if (job instanceof ConfigurableBeanJob) {
                BeanDescriptor<?> descriptor = ((ConfigurableBeanJob<?>) job).getDescriptor();
                label.append(descriptor.getDisplayName());
            } else {
                label.append(job.toString());
            }
        } else {
            label.append(jobName);
        }

        if (job instanceof AnalyzerJob) {
            AnalyzerJob analyzerJob = (AnalyzerJob) job;
            if (includeDescriptorName && !Strings.isNullOrEmpty(jobName)) {
                label.append(" (");
                label.append(analyzerJob.getDescriptor().getDisplayName());
                label.append(')');
            }

            final InputColumn<?>[] input = analyzerJob.getInput();
            if (input.length == 1) {
                if (input[0].getName().equals(jobName)) {
                    // special case where jobName is the same as the single
                    // input column - in that case we'll leave out the column
                    // name
                    includeInputColumnNames = false;
                }
            }
            if (includeInputColumnNames && input.length > 0) {

                label.append(" (");
                if (input.length < 5) {
                    for (int i = 0; i < input.length; i++) {
                        if (i != 0) {
                            label.append(',');
                        }
                        label.append(input[i].getName());
                    }
                } else {
                    label.append(input.length);
                    label.append(" columns");
                }
                label.append(")");
            }

            final ComponentRequirement requirement = analyzerJob.getComponentRequirement();
            if (includeRequirements && requirement != null) {
                label.append(" (");
                label.append(requirement.toString());
                label.append(")");
            }
        }

        return label.toString();
    }
816471
private synchronized String getJobNotAdmittedReason(JobInProgress job,
      JobAdmissionWaitInfo waitInfo) {
    JobInfo jobInfo = infos.get(job);
    if (jobInfo == null) {
      return "Unknown, can't find job";
    }
    AdmissionControlData admissionControlData =
        jobInitializer.getAdmissionControlData();
    return NotAdmittedJobInfo.getReasoning(
        adjustClusterwideReason(
            admissionControlData, jobInfo.reason, poolMgr.getPoolName(job)),
            jobInfo.reasonLimit, jobInfo.actualValue,
            jobInfo.hardAdmissionPosition, waitInfo);
  }
814718
public static JobID forName(String str) throws IllegalArgumentException {
    if(str == null)
      return null;
    try {
      String[] parts = str.split("_");
      if(parts.length == 3) {
        if(parts[0].equals(JOB)) {
          return new org.apache.hadoop.mapred.JobID(parts[1], 
                                                    Integer.parseInt(parts[2]));
        }
      }
    }catch (Exception ex) {//fall below
    }
    throw new IllegalArgumentException("JobId string : " + str 
        + " is not properly formed");
  }
291567
public static String getJobIdentifier() {
    // TODO[JIRA REEF-818]: currently we obtain the job id directly by parsing execution (container) directory path
    // #845 is open to get the id from RM properly
    for (File directory = new File(System.getProperty("user.dir"));
         directory != null; directory = directory.getParentFile()) {
      final String currentDirectoryName = directory.getName();
      if (currentDirectoryName.toLowerCase().contains("application_")) {
        return currentDirectoryName;
      }
    }
    // cannot find a directory that contains application_, presumably we are on local runtime
    // again, this is a hack for now, we need #845 as a proper solution
    return "REEF_LOCAL_RUNTIME";
  }
1184536
public JobDetails getJobByJobID(QualifiedJobId jobId, boolean populateTasks)
      throws IOException {
    JobDetails job = null;
    JobKey key = idService.getJobKeyById(jobId);
    if (key != null) {
      byte[] historyKey = jobKeyConv.toBytes(key);
      Table historyTable =
          hbaseConnection.getTable(TableName.valueOf(Constants.HISTORY_TABLE));
      Result result = historyTable.get(new Get(historyKey));
      historyTable.close();
      if (result != null && !result.isEmpty()) {
        job = new JobDetails(key);
        job.populate(result);
        if (populateTasks) {
          populateTasks(job);
        }
      }
    }
    return job;
  }
991949
@Override
	public String getTagName(long jobExecutionId) {
		logger.entering(CLASSNAME, "getTagName", jobExecutionId);
		String apptag = null;
		Connection conn = null;
		PreparedStatement statement = null;
		ResultSet rs = null;
		String query = "SELECT A.apptag FROM jobinstancedata A INNER JOIN executioninstancedata B ON A.jobinstanceid = B.jobinstanceid"
				+ " WHERE B.jobexecid = ?";
		try {
			conn = getConnection();
			statement = conn.prepareStatement(query);
			statement.setLong(1, jobExecutionId);
			rs = statement.executeQuery();
			if(rs.next()) {
				apptag = rs.getString(1);
			}
		} catch (SQLException e) {
			throw new PersistenceException(e);
		} finally {
			cleanupConnection(conn, rs, statement);
		}
		logger.exiting(CLASSNAME, "getTagName");
		return apptag;
	}
1191898
@Trivial
    final String getName() {
        Map<String, String> execProps = getExecutionProperties();
        String taskName = execProps == null ? null : execProps.get(ManagedTask.IDENTITY_NAME);
        return taskName == null ? task.toString() : taskName;
    }
442924
@SuppressWarnings("WeakerAccess")
  public ApiFuture<AppProfile> getAppProfileAsync(String instanceId, String appProfileId) {
    String name = NameUtil.formatAppProfileName(projectId, instanceId, appProfileId);

    GetAppProfileRequest request =
        GetAppProfileRequest.newBuilder().setName(name.toString()).build();

    return ApiFutures.transform(
        stub.getAppProfileCallable().futureCall(request),
        new ApiFunction<com.google.bigtable.admin.v2.AppProfile, AppProfile>() {
          @Override
          public AppProfile apply(com.google.bigtable.admin.v2.AppProfile proto) {
            return AppProfile.fromProto(proto);
          }
        },
        MoreExecutors.directExecutor());
  }
845076
public String getNamefromId(int id) {
        return (String) sqlService.getFromTable(
            Constants.PROFILE_PROFILE_NAME, Constants.GENERIC_ID,
            id, Constants.DB_TABLE_PROFILE);
    }
746159
public static String getDirName(Props props) {
    String dirSuffix = props.get(CommonJobProperties.NESTED_FLOW_PATH);

    if ((dirSuffix == null) || (dirSuffix.length() == 0)) {
      dirSuffix = props.get(CommonJobProperties.JOB_ID);
      if ((dirSuffix == null) || (dirSuffix.length() == 0)) {
        throw new RuntimeException("azkaban.flow.nested.path and azkaban.job.id were not set");
      }
    }

    return "_resources_" + dirSuffix.replace(':', '_');
  }
721814
public String getApplicationId() {
		String applicationId = null;
		Integer applicationIdObject = querySingleTypedResult(
				"PRAGMA application_id", null, GeoPackageDataType.MEDIUMINT);
		if (applicationIdObject != null) {
			try {
				applicationId = new String(ByteBuffer.allocate(4)
						.putInt(applicationIdObject).array(), "UTF-8");
			} catch (UnsupportedEncodingException e) {
				throw new GeoPackageException(
						"Unexpected application id character encoding", e);
			}
		}
		return applicationId;
	}
681454
public String getApplicationName() {
        if (this.applicationName != null)
            return this.applicationName;
        else if (webApp != null)
            return this.webApp.getApplicationName();
        else
            return null;

    }
924623
public boolean cancelJobFromId(String jobName) {
    // [START ]
    JobId jobId = JobId.of(jobName);
    boolean success = bigquery.cancel(jobId);
    if (success) {
      // job was cancelled
    } else {
      // job was not found
    }
    // [END ]
    return success;
  }