[ https://issues.apache.org/jira/browse/TWILL-195?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15549931#comment-15549931 ]
ASF GitHub Bot commented on TWILL-195: -------------------------------------- Github user chtyim commented on a diff in the pull request: https://github.com/apache/twill/pull/13#discussion_r82069017 --- Diff: twill-core/src/main/java/org/apache/twill/internal/json/TwillRuntimeSpecificationCodec.java --- @@ -0,0 +1,91 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.twill.internal.json; + +import com.google.common.reflect.TypeToken; +import com.google.gson.JsonDeserializationContext; +import com.google.gson.JsonDeserializer; +import com.google.gson.JsonElement; +import com.google.gson.JsonObject; +import com.google.gson.JsonParseException; +import com.google.gson.JsonSerializationContext; +import com.google.gson.JsonSerializer; +import org.apache.twill.api.TwillSpecification; +import org.apache.twill.api.logging.LogEntry; +import org.apache.twill.internal.RunIds; +import org.apache.twill.internal.TwillRuntimeSpecification; + +import java.lang.reflect.Type; +import java.net.URI; + +/** + * Codec for serializing and deserializing a {@link TwillRuntimeSpecification} object using json. + */ +final class TwillRuntimeSpecificationCodec implements JsonSerializer<TwillRuntimeSpecification>, + JsonDeserializer<TwillRuntimeSpecification> { + + private static final String FS_USER = "fsUser"; + private static final String TWILL_APP_DIR = "twillAppDir"; + private static final String ZK_CONNECT_STR = "zkConnectStr"; + private static final String TWILL_RUNID = "twillRunId"; + private static final String TWILL_APP_NAME = "twillAppName"; + private static final String RESERVED_MEMORY = "reservedMemory"; + private static final String RM_SCHEDULER_ADDR = "rmSchedulerAddr"; + private static final String LOG_LEVEL = "logLevel"; + private static final String TWILL_SPEC = "twillSpecification"; + + @Override + public JsonElement serialize(TwillRuntimeSpecification src, Type typeOfSrc, JsonSerializationContext context) { + JsonObject json = new JsonObject(); + json.addProperty(FS_USER, src.getFsUser()); + json.addProperty(TWILL_APP_DIR, src.getTwillAppDir().toASCIIString()); + json.addProperty(ZK_CONNECT_STR, src.getZkConnectStr()); + json.addProperty(TWILL_RUNID, src.getTwillRunId().getId()); + json.addProperty(TWILL_APP_NAME, src.getTwillAppName()); + json.addProperty(RESERVED_MEMORY, src.getReservedMemory()); + if (src.getRmSchedulerAddr() != null) { + json.addProperty(RM_SCHEDULER_ADDR, src.getRmSchedulerAddr()); + } + if (src.getLogLevel() != null) { + json.addProperty(LOG_LEVEL, src.getLogLevel().name()); + } + json.add(TWILL_SPEC, context.serialize(src.getTwillSpecification(), + new TypeToken<TwillSpecification>() { }.getType())); + return json; + } + + @Override + public TwillRuntimeSpecification deserialize(JsonElement json, Type typeOfT, + JsonDeserializationContext context) throws JsonParseException { --- End diff -- The alignment is awkward. You should have the parameters aligned. ```java deserialize(JsonElement ... JsonDeserializationContext ...) ``` > Add TwillRuntimeSpecification for twill application > --------------------------------------------------- > > Key: TWILL-195 > URL: https://issues.apache.org/jira/browse/TWILL-195 > Project: Apache Twill > Issue Type: Improvement > Components: core > Reporter: Yaojie Feng > > Now we have RuntimeSpecification for twill runnable. We should also have a > TwillRuntimeSpecification to pass runtime requirements for twill applications. -- This message was sent by Atlassian JIRA (v6.3.4#6332)