Skip to content
This repository has been archived by the owner on May 12, 2021. It is now read-only.

TWILL-195 Add TwillRuntimeSpecification #13

Closed
wants to merge 1 commit into from
Closed

TWILL-195 Add TwillRuntimeSpecification #13

wants to merge 1 commit into from

Conversation

yaojiefeng
Copy link
Contributor

JIRA: https://issues.apache.org/jira/browse/TWILL-195

Summary: This PR is a prerequisite of TWILL-138. Add TwillRuntimeSpecification for twill application which includes TwillSpecification and other environment variables that the applications will need later.

/**
* Represents runtime specification of a {@link TwillApplication}.
*/
public interface TwillRuntimeSpecification {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This class shouldn't be in twill-api. It is only used internally. Also, we don't need an interface and an implementation. Just make this a concrete class.

Copy link
Member

@chtyim chtyim left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did a pass over the change. Please address the comments.

* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.twill.internal;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why this class has to be in twill-api? I only see this class being used inside twill-yarn.


private final TwillSpecification twillSpecification;

private final String fsUser;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why everything are of String type? E.g. twillRunId should be a RunId type, reservedMemory should be int, twillAppDir should be an URI. Please use proper types.

/**
* Constants for twill environment variable names.
*/
public static final class Environments {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why moved from EnvKeys? What are they for?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

They are initially used in EnvKeys to pass system env variables. But with the use of TwillRuntimeSpecification, they are no longer used as keys. They are used as constants in configuration or error messages so I move them to Constants class

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Then you should not have them under environment

TwillSpecification twillSpecification = context.deserialize(
jsonObj.get(TWILL_SPEC), new TypeToken<TwillSpecification>() { }.getType());
return new TwillRuntimeSpecification(twillSpecification,
jsonObj.has(FS_USER) ? jsonObj.get(FS_USER).getAsString() : null,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see constructor of TwillRuntimeSpecification has @Nullable for the parameters. Please annotate accordingly for parameters that are allowed to have null values.

if (fsUser == null) {
throw new IllegalStateException("Missing environment variable " + EnvKeys.TWILL_FS_USER);
throw new IllegalStateException("Missing environment variable " + Constants.TWILL_FS_USER);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This error message is not right. The fs user now comes in the runtime spec, not from env, right? In fact, can this happen?

*/
protected static Location createAppLocation(final Configuration conf) {
protected static Location createAppLocation(final Configuration conf, String fsUser, String appDirectory) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

appDirectory should be URI as it is in the runtime spec, right?

return reservedMemory;
}

public String getRmSchedulerAddr() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For those that can be null, annotate the method with @Nullable as well.

@@ -22,36 +22,25 @@
*/
public final class EnvKeys {

public static final String TWILL_ZK_CONNECT = "TWILL_ZK_CONNECT";
public static final String TWILL_APP_RUN_ID = "TWILL_APP_RUN_ID";
public static final String TWILL_RUN_ID = "TWILL_RUN_ID";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this still in the env? Isn't that we have the runid in the runtime spec?

Copy link
Contributor Author

@yaojiefeng yaojiefeng Oct 5, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This key is to provide runId for TwillContainerService, which is not the application id and it is added in TwillContainerLauncher as a system variable so we cannot remove it.

json.addProperty(RM_SCHEDULER_ADDR, src.getRmSchedulerAddr());
}
if (src.getLogLevel() != null) {
json.addProperty(LOG_LEVEL, src.getLogLevel().toString());
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should serialize with the .name(), not .toString().

String appLogLevel = System.getenv(EnvKeys.TWILL_APP_LOG_LEVEL);

return Strings.isNullOrEmpty(appLogLevel) ? super.getLoggerLevel(logger) : appLogLevel;
return logLevel == null ? super.getLoggerLevel(logger) : logLevel.toString();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should use .name() instead of .toString()

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed

Copy link
Member

@chtyim chtyim left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Two more comments.


@Override
public TwillRuntimeSpecification deserialize(JsonElement json, Type typeOfT,
JsonDeserializationContext context) throws JsonParseException {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The alignment is awkward. You should have the parameters aligned.

deserialize(JsonElement ...
            JsonDeserializationContext ...)

@@ -169,7 +172,7 @@ public Reader getInput() throws IOException {
}

private int getReservedMemory() {
String value = System.getenv(EnvKeys.TWILL_RESERVED_MEMORY_MB);
String value = Integer.toString(twillRuntimeSpec.getReservedMemory());
if (value == null) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This logic doesn't make sense. The twillRuntimeSpec.getReservedMemory already return an int. It can never be null. This method is unnecessary. Just call twillRuntimeSpec.getReservedMemory whenever needed.

@chtyim
Copy link
Member

chtyim commented Oct 5, 2016

LGTM. Please squash the commits.

@asfgit asfgit closed this in 6c7d32a Oct 5, 2016
@yaojiefeng yaojiefeng deleted the feature/add-TwillRuntimeSpecification branch October 5, 2016 22:37
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
2 participants