Skip to content

Commit

Permalink
Create ExecuteProcessReporter (apache#9674)
Browse files Browse the repository at this point in the history
  • Loading branch information
tristaZero authored Mar 16, 2021
1 parent 7d3b42c commit a007cb3
Show file tree
Hide file tree
Showing 5 changed files with 128 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@
<artifactId>shardingsphere-infra-context</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.apache.shardingsphere</groupId>
<artifactId>shardingsphere-infra-executor</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.apache.shardingsphere</groupId>
<artifactId>shardingsphere-governance-core</artifactId>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*
* 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.shardingsphere.governance.context.process;

import org.apache.shardingsphere.infra.binder.statement.SQLStatementContext;
import org.apache.shardingsphere.infra.executor.kernel.model.ExecutionGroupContext;
import org.apache.shardingsphere.infra.executor.sql.execute.engine.SQLExecutionUnit;
import org.apache.shardingsphere.infra.executor.sql.process.model.ExecuteProcessStatus;
import org.apache.shardingsphere.infra.executor.sql.process.spi.ExecuteProcessReporter;

/**
* Governance execute process reporter.
*/
public final class GovernanceExecuteProcessReporter implements ExecuteProcessReporter {

@Override
public void report(final SQLStatementContext<?> context, final ExecutionGroupContext<SQLExecutionUnit> executionGroupContext, final ExecuteProcessStatus status) {
// TODO :Call API of configCenter
}

@Override
public void report(final String executionID, final SQLExecutionUnit executionUnit, final ExecuteProcessStatus status) {
// TODO :Call API of configCenter
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#
# 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.
#

org.apache.shardingsphere.governance.context.process.GovernanceExecuteProcessReporter
Original file line number Diff line number Diff line change
Expand Up @@ -20,39 +20,48 @@
import lombok.AccessLevel;
import lombok.NoArgsConstructor;
import org.apache.shardingsphere.infra.binder.statement.SQLStatementContext;
import org.apache.shardingsphere.infra.eventbus.ShardingSphereEventBus;
import org.apache.shardingsphere.infra.executor.kernel.model.ExecutionGroupContext;
import org.apache.shardingsphere.infra.executor.sql.execute.engine.SQLExecutionUnit;
import org.apache.shardingsphere.infra.executor.sql.process.event.ExecuteProcessCreatedEvent;
import org.apache.shardingsphere.infra.executor.sql.process.event.ExecuteProcessUnitCreatedEvent;
import org.apache.shardingsphere.infra.executor.sql.process.model.ExecuteProcessStatus;
import org.apache.shardingsphere.infra.executor.sql.process.spi.ExecuteProcessReporter;
import org.apache.shardingsphere.infra.spi.ShardingSphereServiceLoader;

import java.util.Collection;

/**
* Execute process engine.
*/
@NoArgsConstructor(access = AccessLevel.PRIVATE)
public final class ExecuteProcessEngine {

private static final Collection<ExecuteProcessReporter> HANDLERS;

static {
ShardingSphereServiceLoader.register(ExecuteProcessReporter.class);
HANDLERS = ShardingSphereServiceLoader.newServiceInstances(ExecuteProcessReporter.class);
}

/**
* Submit.
* Initialize.
*
* @param context context
* @param executionGroupContext execution group context
*/
public static void submit(final SQLStatementContext<?> context, final ExecutionGroupContext<SQLExecutionUnit> executionGroupContext) {
if (ExecuteProcessStrategyEvaluator.evaluate(context, executionGroupContext)) {
ShardingSphereEventBus.getInstance().post(new ExecuteProcessCreatedEvent(executionGroupContext));
public static void initialize(final SQLStatementContext<?> context, final ExecutionGroupContext<SQLExecutionUnit> executionGroupContext) {
if (!HANDLERS.isEmpty() && ExecuteProcessStrategyEvaluator.evaluate(context, executionGroupContext)) {
HANDLERS.iterator().next().report(context, executionGroupContext, ExecuteProcessStatus.DOING);
}
}

/**
* Submit.
* Complete.
*
* @param executionID execution ID
* @param executionUnit execution unit
* @param status status
*/
public static void submit(final String executionID, final SQLExecutionUnit executionUnit, final ExecuteProcessStatus status) {
ShardingSphereEventBus.getInstance().post(new ExecuteProcessUnitCreatedEvent(executionID, executionUnit, status));
public static void complete(final String executionID, final SQLExecutionUnit executionUnit) {
if (!HANDLERS.isEmpty()) {
HANDLERS.iterator().next().report(executionID, executionUnit, ExecuteProcessStatus.DONE);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/*
* 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.shardingsphere.infra.executor.sql.process.spi;

import org.apache.shardingsphere.infra.binder.statement.SQLStatementContext;
import org.apache.shardingsphere.infra.executor.kernel.model.ExecutionGroupContext;
import org.apache.shardingsphere.infra.executor.sql.execute.engine.SQLExecutionUnit;
import org.apache.shardingsphere.infra.executor.sql.process.model.ExecuteProcessStatus;

/**
* Execute process report.
*/
public interface ExecuteProcessReporter {

/**
* Report the summary of this task.
* @param context context
* @param executionGroupContext execution group context
* @param status status
*/
void report(SQLStatementContext<?> context, ExecutionGroupContext<SQLExecutionUnit> executionGroupContext, ExecuteProcessStatus status);

/**
* Report a unit of this task.
* @param executionID execution ID
* @param executionUnit execution unit
* @param status status
*/
void report(String executionID, SQLExecutionUnit executionUnit, ExecuteProcessStatus status);
}

0 comments on commit a007cb3

Please sign in to comment.