Browse Source
* updates * move FetchTaskThread logic to WorkerNettyRequestProcessor * add NettyRemotingClient to scheduler thread * refactor TaskScheduleThread, add TaskInstanceCallbackServicepull/2/head
Tboy
5 years ago
committed by
GitHub
8 changed files with 178 additions and 37 deletions
@ -1 +1 @@
|
||||
/*
* 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.dolphinscheduler.remote.command;
public enum CommandType {
/**
* roll view log request
*/
ROLL_VIEW_LOG_REQUEST,
/**
* roll view log response
*/
ROLL_VIEW_LOG_RESPONSE,
/**
* view whole log request
*/
VIEW_WHOLE_LOG_REQUEST,
/**
* view whole log response
*/
VIEW_WHOLE_LOG_RESPONSE,
/**
* get log bytes request
*/
GET_LOG_BYTES_REQUEST,
/**
* get log bytes response
*/
GET_LOG_BYTES_RESPONSE,
WORKER_REQUEST,
MASTER_RESPONSE,
/**
* execute task request
*/
EXECUTE_TASK_REQUEST,
/**
* execute task response
*/
EXECUTE_TASK_RESPONSE,
/**
* ping
*/
PING,
/**
* pong
*/
PONG;
} |
||||
/*
* 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.dolphinscheduler.remote.command;
public enum CommandType {
/**
* roll view log request
*/
ROLL_VIEW_LOG_REQUEST,
/**
* roll view log response
*/
ROLL_VIEW_LOG_RESPONSE,
/**
* view whole log request
*/
VIEW_WHOLE_LOG_REQUEST,
/**
* view whole log response
*/
VIEW_WHOLE_LOG_RESPONSE,
/**
* get log bytes request
*/
GET_LOG_BYTES_REQUEST,
/**
* get log bytes response
*/
GET_LOG_BYTES_RESPONSE,
WORKER_REQUEST,
MASTER_RESPONSE,
/**
* execute task request
*/
EXECUTE_TASK_REQUEST,
/**
* execute task ack
*/
EXECUTE_TASK_ACK,
/**
* execute task response
*/
EXECUTE_TASK_RESPONSE,
/**
* ping
*/
PING,
/**
* pong
*/
PONG;
} |
@ -0,0 +1 @@
|
||||
/*
* 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.dolphinscheduler.remote.command;
import org.apache.dolphinscheduler.remote.utils.FastJsonSerializer;
import java.io.Serializable;
import java.util.Date;
/**
* execute task request command
*/
public class ExecuteTaskAckCommand implements Serializable {
private int taskInstanceId;
private Date startTime;
private String host;
private int status;
private String logPath;
private String executePath;
public Date getStartTime() {
return startTime;
}
public void setStartTime(Date startTime) {
this.startTime = startTime;
}
public String getHost() {
return host;
}
public void setHost(String host) {
this.host = host;
}
public int getStatus() {
return status;
}
public void setStatus(int status) {
this.status = status;
}
public int getTaskInstanceId() {
return taskInstanceId;
}
public void setTaskInstanceId(int taskInstanceId) {
this.taskInstanceId = taskInstanceId;
}
public String getLogPath() {
return logPath;
}
public void setLogPath(String logPath) {
this.logPath = logPath;
}
public String getExecutePath() {
return executePath;
}
public void setExecutePath(String executePath) {
this.executePath = executePath;
}
/**
* package request command
*
* @return command
*/
public Command convert2Command(long opaque){
Command command = new Command(opaque);
command.setType(CommandType.EXECUTE_TASK_ACK);
byte[] body = FastJsonSerializer.serialize(this);
command.setBody(body);
return command;
}
} |
@ -1 +1 @@
|
||||
/*
* 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.dolphinscheduler.remote.command;
import org.apache.dolphinscheduler.remote.utils.FastJsonSerializer;
import java.io.Serializable;
import java.util.concurrent.atomic.AtomicLong;
/**
* execute task response command
*/
public class ExecuteTaskResponseCommand implements Serializable {
/**
* task id
*/
concurrent.atomic.AtomicLong;
/**
concurrent.atomic.AtomicLong;
concurrent.atomic.AtomicLong;
*/
concurrent.atomic.AtomicLong;
/**
concurrent.atomic.AtomicLong;
/**
*/
concurrent.atomic.AtomicLong;
* execute task response command
/**
concurrent.atomic.AtomicLong;
*/
*/
concurrent.atomic.AtomicLong;
public class ExecuteTaskResponseCommand implements Serializable {
/**
* execute count
*/
concurrent.atomic.AtomicLong;
* task id
/**
* execute time
*/
private long executeTime;
public String getAttemptId() {
return attemptId;
}
* execute task response command
*/
/**
public class ExecuteTaskResponseCommand implements Serializable {
/**
}
public void setTaskId(String taskId) {
this.taskId = taskId;
}
/**
return result;
/**
public void setResult(Object result) {
this.result = result;
}
/**
* execute task response command
/**
*/
}
/**
public class ExecuteTaskResponseCommand implements Serializable {
/**
/**
}
/**
* task id
/**
*/
}
* execute task response command
* execute task response command
concurrent.atomic.AtomicLong;
}
public long getExecuteTime() {
* execute task response command
/**
/**
* execute task response command
* execute task response command
* execute task response command
*/
}
* execute task response command
public class ExecuteTaskResponseCommand implements Serializable {
Command command = new Command();
* execute task response command
* task id
byte[] body = FastJsonSerializer.serialize(this);
*/
return command;
}
} |
||||
/*
* 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.dolphinscheduler.remote.command;
import org.apache.dolphinscheduler.remote.utils.FastJsonSerializer;
import java.io.Serializable;
import java.util. */
/**
*/
* execute task response command
*/
*/
*/
public class ExecuteTaskResponseCommand implements Serializable {
*/
/**
*/
* task id
*/
*/
public class ExecuteTaskResponseCommand implements Serializable {
public class ExecuteTaskResponseCommand implements Serializable {
concurrent.atomic.AtomicLong;
public class ExecuteTaskResponseCommand implements Serializable {
}
public class ExecuteTaskResponseCommand implements Serializable {
/**
public class ExecuteTaskResponseCommand implements Serializable {
* execute task response command
*/
private int taskInstanceId;
*/
* execute task response command
/**
public class ExecuteTaskResponseCommand implements Serializable {
/**
*/
public class ExecuteTaskResponseCommand implements Serializable {
* task id
*/
* execute task response command
*/
* execute task response command
public class ExecuteTaskResponseCommand implements Serializable {
/**
* end time
public class ExecuteTaskResponseCommand implements Serializable {
*/
/**
public int getTaskInstanceId() {
/**
public class ExecuteTaskResponseCommand implements Serializable {
/**
/**
public class ExecuteTaskResponseCommand implements Serializable {
}
/**
* execute task response command
/**
*/
}
/**
public class ExecuteTaskResponseCommand implements Serializable {
/**
/**
}
/**
* task id
/**
*/
public class ExecuteTaskResponseCommand implements Serializable {
*/
* execute task response command
public void setEndTime(Date endTime) {
this.endTime = endTime;
}
*/
* execute task response command
* task id
* task id
/**
* task id
* execute task response command
* task id
*/
* task id
public class ExecuteTaskResponseCommand implements Serializable {
* task id
/**
public class ExecuteTaskResponseCommand implements Serializable {
} |
@ -0,0 +1,49 @@
|
||||
/* |
||||
* 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.dolphinscheduler.server.worker.processor; |
||||
|
||||
import io.netty.channel.Channel; |
||||
|
||||
|
||||
public class CallbackChannel { |
||||
|
||||
private Channel channel; |
||||
|
||||
private long opaque; |
||||
|
||||
public CallbackChannel(Channel channel, long opaque) { |
||||
this.channel = channel; |
||||
this.opaque = opaque; |
||||
} |
||||
|
||||
public Channel getChannel() { |
||||
return channel; |
||||
} |
||||
|
||||
public void setChannel(Channel channel) { |
||||
this.channel = channel; |
||||
} |
||||
|
||||
public long getOpaque() { |
||||
return opaque; |
||||
} |
||||
|
||||
public void setOpaque(long opaque) { |
||||
this.opaque = opaque; |
||||
} |
||||
} |
@ -0,0 +1,76 @@
|
||||
/* |
||||
* 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.dolphinscheduler.server.worker.processor; |
||||
|
||||
|
||||
import io.netty.channel.Channel; |
||||
import io.netty.channel.ChannelFuture; |
||||
import io.netty.channel.ChannelFutureListener; |
||||
import org.apache.dolphinscheduler.remote.command.ExecuteTaskAckCommand; |
||||
import org.apache.dolphinscheduler.remote.command.ExecuteTaskResponseCommand; |
||||
|
||||
import java.util.concurrent.ConcurrentHashMap; |
||||
|
||||
public class TaskInstanceCallbackService { |
||||
|
||||
private static final ConcurrentHashMap<Integer, CallbackChannel> CALL_BACK_CHANNELS = new ConcurrentHashMap<>(); |
||||
|
||||
public void addCallbackChannel(int taskInstanceId, CallbackChannel channel){ |
||||
CALL_BACK_CHANNELS.put(taskInstanceId, channel); |
||||
} |
||||
|
||||
public CallbackChannel getCallbackChannel(int taskInstanceId){ |
||||
CallbackChannel callbackChannel = CALL_BACK_CHANNELS.get(taskInstanceId); |
||||
if(callbackChannel.getChannel().isActive()){ |
||||
return callbackChannel; |
||||
} |
||||
Channel newChannel = createChannel(); |
||||
callbackChannel.setChannel(newChannel); |
||||
CALL_BACK_CHANNELS.put(taskInstanceId, callbackChannel); |
||||
return callbackChannel; |
||||
} |
||||
|
||||
public void remove(int taskInstanceId){ |
||||
CALL_BACK_CHANNELS.remove(taskInstanceId); |
||||
} |
||||
|
||||
public void sendAck(int taskInstanceId, ExecuteTaskAckCommand ackCommand){ |
||||
CallbackChannel callbackChannel = getCallbackChannel(taskInstanceId); |
||||
callbackChannel.getChannel().writeAndFlush(ackCommand.convert2Command(callbackChannel.getOpaque())); |
||||
} |
||||
|
||||
public void sendResult(int taskInstanceId, ExecuteTaskResponseCommand responseCommand){ |
||||
CallbackChannel callbackChannel = getCallbackChannel(taskInstanceId); |
||||
callbackChannel.getChannel().writeAndFlush(responseCommand.convert2Command()).addListener(new ChannelFutureListener(){ |
||||
|
||||
@Override |
||||
public void operationComplete(ChannelFuture future) throws Exception { |
||||
if(future.isSuccess()){ |
||||
remove(taskInstanceId); |
||||
return; |
||||
} |
||||
} |
||||
}); |
||||
} |
||||
|
||||
//TODO
|
||||
private Channel createChannel(){ |
||||
return null; |
||||
} |
||||
|
||||
} |
Loading…
Reference in new issue