Skip to content

Commit

Permalink
Translate engineconn-plugins-trino service classes from Scala to Java (
Browse files Browse the repository at this point in the history
  • Loading branch information
ChengJie1053 committed May 10, 2023
1 parent 29cf010 commit 632191a
Show file tree
Hide file tree
Showing 16 changed files with 932 additions and 808 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
/*
* 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.linkis.engineplugin.trino;

import org.apache.linkis.engineplugin.trino.builder.TrinoProcessEngineConnLaunchBuilder;
import org.apache.linkis.engineplugin.trino.factory.TrinoEngineConnFactory;
import org.apache.linkis.manager.engineplugin.common.EngineConnPlugin;
import org.apache.linkis.manager.engineplugin.common.creation.EngineConnFactory;
import org.apache.linkis.manager.engineplugin.common.launch.EngineConnLaunchBuilder;
import org.apache.linkis.manager.engineplugin.common.resource.EngineResourceFactory;
import org.apache.linkis.manager.engineplugin.common.resource.GenericEngineResourceFactory;
import org.apache.linkis.manager.label.entity.Label;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Objects;

public class TrinoEngineConnPlugin implements EngineConnPlugin {

private Object resourceLocker = new Object();
private Object engineFactoryLocker = new Object();
private volatile EngineResourceFactory engineResourceFactory;
private volatile EngineConnFactory engineFactory;
private final List<Label<?>> defaultLabels = new ArrayList<>();

@Override
public void init(Map<String, Object> params) {}

@Override
public EngineResourceFactory getEngineResourceFactory() {
if (Objects.isNull(engineResourceFactory)) {
synchronized (resourceLocker) {
if (Objects.isNull(engineResourceFactory)) {
engineResourceFactory = new GenericEngineResourceFactory();
}
}
}
return engineResourceFactory;
}

@Override
public EngineConnLaunchBuilder getEngineConnLaunchBuilder() {
return new TrinoProcessEngineConnLaunchBuilder();
}

@Override
public EngineConnFactory getEngineConnFactory() {
if (Objects.isNull(engineFactory)) {
synchronized (engineFactoryLocker) {
if (Objects.isNull(engineFactory)) {
engineFactory = new TrinoEngineConnFactory();
}
}
}
return engineFactory;
}

@Override
public List<Label<?>> getDefaultLabels() {
return defaultLabels;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,23 +15,21 @@
* limitations under the License.
*/

package org.apache.linkis.engineplugin.trino.builder
package org.apache.linkis.engineplugin.trino.builder;

import org.apache.linkis.engineplugin.trino.conf.TrinoConfiguration
import org.apache.linkis.manager.engineplugin.common.launch.process.JavaProcessEngineConnLaunchBuilder
import org.apache.linkis.manager.label.entity.engine.UserCreatorLabel
import org.apache.linkis.engineplugin.trino.conf.TrinoConfiguration;
import org.apache.linkis.manager.engineplugin.common.launch.process.JavaProcessEngineConnLaunchBuilder;
import org.apache.linkis.manager.label.entity.engine.UserCreatorLabel;

import org.apache.commons.lang3.StringUtils
public class TrinoProcessEngineConnLaunchBuilder extends JavaProcessEngineConnLaunchBuilder {

class TrinoProcessEngineConnLaunchBuilder extends JavaProcessEngineConnLaunchBuilder {

override def getEngineStartUser(label: UserCreatorLabel): String = {
if (TrinoConfiguration.TRINO_USER_ISOLATION_MODE.getValue) {
/* using user label if user is blank */
label.getUser
@Override
public String getEngineStartUser(UserCreatorLabel label) {
if (TrinoConfiguration.TRINO_USER_ISOLATION_MODE.getValue()) {
// Using user label if user is blank
return label.getUser();
} else {
TrinoConfiguration.TRINO_DEFAULT_USER.getValue
return TrinoConfiguration.TRINO_DEFAULT_USER.getValue();
}
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
/*
* 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.linkis.engineplugin.trino.conf;

import org.apache.linkis.common.conf.CommonVars;
import org.apache.linkis.storage.utils.StorageConfiguration;

public class TrinoConfiguration {

public static final CommonVars<Integer> ENGINE_CONCURRENT_LIMIT =
CommonVars.apply("linkis.engineconn.concurrent.limit", 100);

public static final CommonVars<Integer> DEFAULT_LIMIT =
CommonVars.apply("linkis.trino.default.limit", 5000);

public static final CommonVars<Long> TRINO_HTTP_CONNECT_TIME_OUT =
CommonVars.apply("linkis.trino.http.connectTimeout.seconds", 60L);

public static final CommonVars<Long> TRINO_HTTP_READ_TIME_OUT =
CommonVars.apply("linkis.trino.http.readTimeout.seconds", 60L);

public static final CommonVars<String> TRINO_URL =
CommonVars.apply("linkis.trino.url", "http://127.0.0.1:8080");

public static final CommonVars<String> TRINO_PASSWORD =
CommonVars.apply("linkis.trino.password", null);

public static final CommonVars<String> TRINO_PASSWORD_CMD =
CommonVars.apply("linkis.trino.password.cmd", null);

public static final CommonVars<String> TRINO_CATALOG =
CommonVars.apply("linkis.trino.catalog", "system");

public static final CommonVars<String> TRINO_SCHEMA = CommonVars.apply("linkis.trino.schema", "");

public static final CommonVars<String> TRINO_SOURCE =
CommonVars.apply("linkis.trino.source", "global");

public static final CommonVars<Boolean> TRINO_SSL_INSECURED =
CommonVars.apply("linkis.trino.ssl.insecured", true);

public static final CommonVars<String> TRINO_SSL_KEYSTORE =
CommonVars.apply("linkis.trino.ssl.keystore", null);

public static final CommonVars<String> TRINO_SSL_KEYSTORE_TYPE =
CommonVars.apply("linkis.trino.ssl.keystore.type", null);

public static final CommonVars<String> TRINO_SSL_KEYSTORE_PASSWORD =
CommonVars.apply("linkis.trino.ssl.keystore.password", null);

public static final CommonVars<String> TRINO_SSL_TRUSTSTORE =
CommonVars.apply("linkis.trino.ssl.truststore", null);

public static final CommonVars<String> TRINO_SSL_TRUSTSTORE_TYPE =
CommonVars.apply("linkis.trino.ssl.truststore.type", null);

public static final CommonVars<String> TRINO_SSL_TRUSTSTORE_PASSWORD =
CommonVars.apply("linkis.trino.ssl.truststore.password", null);

public static final CommonVars<Boolean> TRINO_FORBID_GRANT =
CommonVars.apply("linkis.trino.forbid.grant", true);

public static final CommonVars<Boolean> TRINO_FORBID_MODIFY_SCHEMA =
CommonVars.apply("linkis.trino.forbid.modifySchema", true);

public static final CommonVars<Boolean> TRINO_USER_ISOLATION_MODE =
CommonVars.apply("linkis.trino.user.isolation.mode", false);

public static final CommonVars<String> TRINO_DEFAULT_USER =
CommonVars.apply(
"linkis.trino.default.start.user", StorageConfiguration.HDFS_ROOT_USER.getValue());

public static final CommonVars<Boolean> TRINO_SQL_HOOK_ENABLED =
CommonVars.apply("linkis.trino.sql.hook.enabled", true, "trino sql hoook");
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/*
* 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.linkis.engineplugin.trino.conf;

import org.apache.linkis.common.conf.Configuration;
import org.apache.linkis.governance.common.protocol.conf.RequestQueryEngineConfigWithGlobalConfig;
import org.apache.linkis.governance.common.protocol.conf.ResponseQueryConfig;
import org.apache.linkis.manager.label.entity.engine.EngineTypeLabel;
import org.apache.linkis.manager.label.entity.engine.UserCreatorLabel;
import org.apache.linkis.protocol.CacheableProtocol;
import org.apache.linkis.rpc.RPCMapCache;

import java.util.Map;

import scala.Tuple2;

public class TrinoEngineConfig
extends RPCMapCache<Tuple2<UserCreatorLabel, EngineTypeLabel>, String, String> {

public TrinoEngineConfig() {
super(Configuration.CLOUD_CONSOLE_CONFIGURATION_SPRING_APPLICATION_NAME().getValue());
}

@Override
public CacheableProtocol createRequest(Tuple2<UserCreatorLabel, EngineTypeLabel> labelTuple) {
return new RequestQueryEngineConfigWithGlobalConfig(labelTuple._1(), labelTuple._2(), null);
}

@Override
public Map<String, String> createMap(Object obj) {
if (obj instanceof ResponseQueryConfig) {
ResponseQueryConfig response = (ResponseQueryConfig) obj;
return response.getKeyAndValue();
} else {
return null;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/*
* 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.linkis.engineplugin.trino.exception;

import org.apache.linkis.common.exception.ErrorException;

public class TrinoClientException extends ErrorException {
public TrinoClientException(String message) {
super(60012, message);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/*
* 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.linkis.engineplugin.trino.exception;

import org.apache.linkis.common.exception.ErrorException;

public class TrinoGrantmaException extends ErrorException {
public TrinoGrantmaException(String message) {
super(60015, message);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,12 @@
* limitations under the License.
*/

package org.apache.linkis.engineplugin.trino.exception
package org.apache.linkis.engineplugin.trino.exception;

import org.apache.linkis.common.exception.ErrorException
import org.apache.linkis.common.exception.ErrorException;

case class TrinoStateInvalidException(message: String)
extends ErrorException(60011, message: String)

case class TrinoClientException(message: String) extends ErrorException(60012, message: String)

case class TrinoSourceGroupException(message: String) extends ErrorException(60013, message: String)

case class TrinoModifySchemaException(message: String)
extends ErrorException(60014, message: String)

case class TrinoGrantmaException(message: String) extends ErrorException(60015, message: String)
public class TrinoModifySchemaException extends ErrorException {
public TrinoModifySchemaException(String message) {
super(60014, message);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/*
* 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.linkis.engineplugin.trino.exception;

import org.apache.linkis.common.exception.ErrorException;

public class TrinoStateInvalidException extends ErrorException {
public TrinoStateInvalidException(String message) {
super(60011, message);
}
}

0 comments on commit 632191a

Please sign in to comment.