Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Runtime related refactoring #1628

Open
wants to merge 16 commits into
base: f-gpu-1579
Choose a base branch
from
4 changes: 2 additions & 2 deletions Jenkinsfile.split
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ stage("Setup Build Environment") {
GitHelper.addTag(version, 'Release of version ' + version)
}
}

if (Boolean.valueOf(params.runDeployTesting)) {
if (params.testingVersion?.trim()) {
version = params.testingVersion.trim()
Expand Down Expand Up @@ -231,7 +231,7 @@ stage("Setup Build Environment") {
withCredentials([usernamePassword(credentialsId: 'docker.gentics.com', usernameVariable: 'repoUsername', passwordVariable: 'repoPassword'),usernamePassword(credentialsId: 'gentics.gpg', usernameVariable: 'gpgKeyName', passwordVariable: 'gpgKeyPass')]) {
withEnv(["TESTCONTAINERS_RYUK_DISABLED=true", "MESH_CONSISTENCY_CHECKS=" + (Boolean.valueOf(params.consistencyChecks) ? "true" : "false")]) {
sh "mvn -fae -Dsurefire.groups=com.gentics.mesh.test.category.FailingTests -Dmaven.javadoc.skip=true -Dskip.cluster.tests=true -Dmaven.test.failure.ignore=true -Dmesh.container.image.prefix=docker.gentics.com/ -B -e -pl '!doc' test -DfailIfNoTests=false"
}
}
}
} finally {
step([$class: 'JUnitResultArchiver', testResults: '**/target/surefire-reports/*.xml'])
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package com.gentics.mesh.core.endpoint.admin;

import com.gentics.mesh.core.rest.admin.localconfig.LocalConfigModel;

import io.reactivex.Single;

/**
* Contract to process the local configuration.
*/
public interface LocalConfigApi {

/**
* Loads the local config currently active in this instance.
* @return
*/
Single<LocalConfigModel> getActiveConfig();

}
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
package com.gentics.mesh.auth;

import javax.inject.Inject;
import javax.inject.Singleton;

import com.gentics.mesh.auth.handler.MeshAnonymousAuthHandler;
import com.gentics.mesh.auth.handler.MeshJWTAuthHandler;
import com.gentics.mesh.etc.config.MeshOptions;
Expand All @@ -12,7 +9,6 @@
/**
* Main location for the Gentics Mesh auth chain.
*/
@Singleton
public class MeshAuthChainImpl implements MeshAuthChain {

private final MeshOAuthService oauthService;
Expand All @@ -21,7 +17,6 @@ public class MeshAuthChainImpl implements MeshAuthChain {

private final MeshAnonymousAuthHandler anonHandler;

@Inject
public MeshAuthChainImpl(MeshOAuthService oauthService, MeshJWTAuthHandler jwtAuthHandler,
MeshAnonymousAuthHandler anonHandler, MeshOptions options) {
this.oauthService = oauthService;
Expand All @@ -39,10 +34,9 @@ public void secure(Route route) {
// Now use the OAuth handler which may be able to authenticate the request - The jwt auth handler may have failed
oauthService.secure(route);

// Finally pass the request through the anonymous handler to fallback to anonymous when enabled
// Pass the request through the anonymous handler to fallback to anonymous when enabled
route.handler(rc -> {
anonHandler.handle(rc);
});
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,15 @@
* Handler to process the local configuration.
*/
@Singleton
public class LocalConfigApi {
public class LocalConfigApiImpl implements LocalConfigApi {

private static final String LOCAL_CONFIG_KEY = "localConfig";

private final Lazy<Vertx> vertx;
private final MeshOptions meshOptions;

@Inject
public LocalConfigApi(Lazy<Vertx> vertx, MeshOptions meshOptions) {
public LocalConfigApiImpl(Lazy<Vertx> vertx, MeshOptions meshOptions) {
this.vertx = vertx;
this.meshOptions = meshOptions;
}
Expand All @@ -44,6 +44,7 @@ public Completable init() {
* Loads the local config currently active in this instance.
* @return
*/
@Override
public Single<LocalConfigModel> getActiveConfig() {
return getMap().flatMap(map -> map.rxGet(LOCAL_CONFIG_KEY).toSingle());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,14 @@
import javax.inject.Inject;
import javax.naming.InvalidNameException;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.gentics.mesh.auth.MeshAuthChain;
import com.gentics.mesh.auth.MeshAuthChainImpl;
import com.gentics.mesh.cli.BootstrapInitializer;
import com.gentics.mesh.core.data.project.HibProject;
import com.gentics.mesh.core.db.Database;
import com.gentics.mesh.core.endpoint.admin.LocalConfigApi;
import com.gentics.mesh.distributed.RequestDelegator;
import com.gentics.mesh.distributed.TopologyChangeReadonlyHandler;
import com.gentics.mesh.etc.config.MeshOptions;
Expand All @@ -25,8 +28,6 @@
import io.vertx.core.eventbus.EventBus;
import io.vertx.core.eventbus.Message;
import io.vertx.core.json.JsonObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import io.vertx.ext.web.handler.BodyHandler;
import io.vertx.ext.web.handler.CorsHandler;
import io.vertx.ext.web.handler.impl.BodyHandlerImpl;
Expand Down Expand Up @@ -54,19 +55,21 @@ public class RouterStorageImpl implements RouterStorage {

public final VersionHandlerImpl versionHandler;

private MeshAuthChainImpl authChain;
private MeshAuthChain authChain;

private final RouterStorageRegistryImpl routerStorageRegistry;

private final RequestDelegator delegator;

private final TopologyChangeReadonlyHandler topologyChangeReadonlyHandler;

private final LocalConfigApi localConfigApi;

@Inject
public RouterStorageImpl(Vertx vertx, MeshOptions options, MeshAuthChainImpl authChain, CorsHandler corsHandler, BodyHandlerImpl bodyHandler,
public RouterStorageImpl(Vertx vertx, MeshOptions options, MeshAuthChain authChain, CorsHandler corsHandler, BodyHandlerImpl bodyHandler,
Lazy<BootstrapInitializer> boot,
Lazy<Database> db, VersionHandlerImpl versionHandler,
RouterStorageRegistryImpl routerStorageRegistry,
RouterStorageRegistryImpl routerStorageRegistry, LocalConfigApi localConfigApi,
RequestDelegator delegator, TopologyChangeReadonlyHandler topologyChangeReadonlyHandler, LivenessManager liveness) {
this.vertx = vertx;
this.options = options;
Expand All @@ -78,6 +81,7 @@ public RouterStorageImpl(Vertx vertx, MeshOptions options, MeshAuthChainImpl aut
this.versionHandler = versionHandler;
this.routerStorageRegistry = routerStorageRegistry;
this.delegator = delegator;
this.localConfigApi = localConfigApi;
this.topologyChangeReadonlyHandler = topologyChangeReadonlyHandler;

// Initialize the router chain. The root router will create additional routers which will be mounted.
Expand Down Expand Up @@ -189,4 +193,9 @@ public RequestDelegator getDelegator() {
public TopologyChangeReadonlyHandler getTopologyChangeReadonlyHandler() {
return topologyChangeReadonlyHandler;
}

@Override
public LocalConfigApi getLocalConfigApi() {
return localConfigApi;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@
import java.util.List;
import java.util.Optional;

import com.gentics.mesh.auth.MeshAuthChainImpl;
import com.gentics.mesh.auth.MeshAuthChain;
import com.gentics.mesh.core.db.Database;
import com.gentics.mesh.core.endpoint.admin.LocalConfigApi;
import com.gentics.mesh.etc.config.MeshOptions;
import com.gentics.mesh.etc.config.VertxOptions;
import com.gentics.mesh.rest.InternalEndpoint;
import com.gentics.mesh.rest.InternalCommonEndpoint;
import com.gentics.mesh.rest.InternalEndpointRoute;
import com.gentics.mesh.rest.impl.InternalEndpointRouteImpl;
import com.gentics.mesh.router.RouterStorage;
Expand All @@ -21,15 +21,15 @@
/**
* An abstract class that should be used when creating new endpoints.
*/
public abstract class AbstractInternalEndpoint implements InternalEndpoint {
public abstract class AbstractInternalEndpoint implements InternalCommonEndpoint {

protected List<InternalEndpointRoute> endpointRoutes = new ArrayList<>();

protected Router localRouter = null;

protected String basePath;

protected MeshAuthChainImpl chain;
protected MeshAuthChain chain;

protected RouterStorage routerStorage;

Expand All @@ -39,7 +39,7 @@ public abstract class AbstractInternalEndpoint implements InternalEndpoint {

protected final MeshOptions options;

protected AbstractInternalEndpoint(String basePath, MeshAuthChainImpl chain, LocalConfigApi localConfigApi, Database db, MeshOptions options) {
protected AbstractInternalEndpoint(String basePath, MeshAuthChain chain, LocalConfigApi localConfigApi, Database db, MeshOptions options) {
this.basePath = basePath;
this.chain = chain;
this.localConfigApi = localConfigApi;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.gentics.mesh.router.route;

import com.gentics.mesh.auth.MeshAuthChainImpl;
import com.gentics.mesh.auth.MeshAuthChain;
import com.gentics.mesh.cli.BootstrapInitializer;
import com.gentics.mesh.core.db.Database;
import com.gentics.mesh.core.endpoint.admin.LocalConfigApi;
Expand All @@ -17,7 +17,7 @@ public abstract class AbstractProjectEndpoint extends AbstractInternalEndpoint {

protected BootstrapInitializer boot;

protected AbstractProjectEndpoint(String basePath, MeshAuthChainImpl chain, BootstrapInitializer boot, LocalConfigApi localConfigApi, Database db, MeshOptions options) {
protected AbstractProjectEndpoint(String basePath, MeshAuthChain chain, BootstrapInitializer boot, LocalConfigApi localConfigApi, Database db, MeshOptions options) {
super(basePath, chain, localConfigApi, db, options);
this.boot = boot;
}
Expand Down
53 changes: 53 additions & 0 deletions common/src/main/java/com/gentics/mesh/util/VertxUtil.java
Original file line number Diff line number Diff line change
@@ -1,13 +1,20 @@
package com.gentics.mesh.util;

import static com.gentics.mesh.core.rest.error.Errors.error;
import static io.netty.handler.codec.http.HttpResponseStatus.BAD_REQUEST;
import static io.netty.handler.codec.http.HttpResponseStatus.OK;
import static org.apache.commons.lang3.StringUtils.isEmpty;

import com.gentics.mesh.context.InternalActionContext;
import com.gentics.mesh.core.rest.common.RestModel;
import com.gentics.mesh.etc.config.MeshOptions;
import com.gentics.mesh.etc.config.MeshUploadOptions;

import io.netty.handler.codec.http.HttpResponseStatus;
import io.reactivex.SingleObserver;
import io.reactivex.disposables.Disposable;
import io.vertx.core.http.HttpServerResponse;
import io.vertx.ext.web.FileUpload;

/**
* Various utility functions regarding Vert.x
Expand Down Expand Up @@ -54,4 +61,50 @@ public void onError(Throwable e) {
}
};
}

/**
* Ember a content-disposition header into the response.
*
* @param response
* @param fileName
* @param type
*/
public static void addContentDispositionHeader(HttpServerResponse response, String fileName, String type) {
String encodedFileNameUTF8 = EncodeUtil.encodeForRFC5597(fileName);
String encodedFileNameISO = EncodeUtil.toISO88591(fileName);

StringBuilder value = new StringBuilder();
value.append(type + ";");
value.append(" filename=\"" + encodedFileNameISO + "\";");
value.append(" filename*=" + encodedFileNameUTF8);
response.putHeader("content-disposition", value.toString());
}

/**
* Validate a Vert.x file upload.
*
* @param ul
* @param fieldName
* @param options
*/
public static void validateFileUpload(FileUpload ul, String fieldName, MeshOptions options) {
MeshUploadOptions uploadOptions = options.getUploadOptions();
long byteLimit = uploadOptions.getByteLimit();

if (ul.size() > byteLimit) {
String humanReadableFileSize = org.apache.commons.io.FileUtils.byteCountToDisplaySize(ul.size());
String humanReadableUploadLimit = org.apache.commons.io.FileUtils.byteCountToDisplaySize(byteLimit);
throw error(BAD_REQUEST, "node_error_uploadlimit_reached", humanReadableFileSize, humanReadableUploadLimit);
}

if (isEmpty(ul.fileName())) {
throw error(BAD_REQUEST, "field_binary_error_emptyfilename", fieldName);
}
if (isEmpty(ul.contentType())) {
throw error(BAD_REQUEST, "field_binary_error_emptymimetype", fieldName);
}
if (ul.size() < 1) {
throw error(BAD_REQUEST, "field_binary_error_emptyfile", fieldName, ul.fileName());
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -463,6 +463,21 @@ public boolean tableExists(Connection connection, UUID versionUuid) {
}
}

/**
* Get the Mesh options.
*
* @return
*/
public HibernateMeshOptions getOptions() {
return options;
}

/**
* Get the database connector properties.
*
* @return
* @throws IOException
*/
protected Properties getConnectorProperties() throws IOException {
Properties buildProperties = new Properties();
buildProperties.load(getClass().getResourceAsStream("/connector.build.properties"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
import com.gentics.mesh.core.data.user.HibUser;
import com.gentics.mesh.core.db.Database;
import com.gentics.mesh.core.db.Tx;
import com.gentics.mesh.core.endpoint.admin.LocalConfigApi;
import com.gentics.mesh.core.endpoint.admin.LocalConfigApiImpl;
import com.gentics.mesh.core.rest.schema.BinaryFieldSchema;
import com.gentics.mesh.core.rest.schema.HtmlFieldSchema;
import com.gentics.mesh.core.rest.schema.SchemaVersionModel;
Expand Down Expand Up @@ -87,12 +87,9 @@
import io.reactivex.Completable;
import io.reactivex.Observable;
import io.vertx.core.Vertx;
import io.vertx.core.VertxException;
import io.vertx.core.VertxOptions;
import io.vertx.core.eventbus.EventBus;
import io.vertx.core.eventbus.EventBusOptions;
import io.vertx.core.impl.VertxInternal;
import io.vertx.core.impl.btc.BlockedThreadEvent;
import io.vertx.core.json.JsonArray;
import io.vertx.core.json.JsonObject;
import io.vertx.core.metrics.MetricsOptions;
Expand Down Expand Up @@ -138,7 +135,7 @@ public abstract class AbstractBootstrapInitializer implements BootstrapInitializ

protected final MetricsOptions metricsOptions;

protected final LocalConfigApi localConfigApi;
protected final LocalConfigApiImpl localConfigApi;

protected final BCryptPasswordEncoder passwordEncoder;

Expand Down Expand Up @@ -171,7 +168,7 @@ protected AbstractBootstrapInitializer(ServerSchemaStorageImpl schemaStorage, Da
Lazy<IndexHandlerRegistryImpl> indexHandlerRegistry, Lazy<CoreVerticleLoader> loader,
HighLevelChangelogSystem highlevelChangelogSystem, CacheRegistry cacheRegistry,
MeshPluginManager pluginManager, MeshOptions options, RouterStorageRegistryImpl routerStorageRegistry,
MetricsOptions metricsOptions, LocalConfigApi localConfigApi, BCryptPasswordEncoder passwordEncoder,
MetricsOptions metricsOptions, LocalConfigApiImpl localConfigApi, BCryptPasswordEncoder passwordEncoder,
MasterElector coordinatorMasterElector, LivenessManager liveness, EventBusLivenessManager eventbusLiveness,
EventBusStore eventBusStore) {
this.schemaStorage = schemaStorage;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import static io.vertx.core.http.HttpMethod.GET;
import static io.vertx.core.http.HttpMethod.POST;

import com.gentics.mesh.auth.MeshAuthChainImpl;
import com.gentics.mesh.auth.MeshAuthChain;
import com.gentics.mesh.context.InternalActionContext;
import com.gentics.mesh.core.db.Database;
import com.gentics.mesh.core.endpoint.admin.LocalConfigApi;
Expand All @@ -21,7 +21,7 @@
*/
public abstract class RolePermissionHandlingEndpoint extends AbstractInternalEndpoint {

protected RolePermissionHandlingEndpoint(String basePath, MeshAuthChainImpl chain, LocalConfigApi localConfigApi, Database db, MeshOptions options) {
protected RolePermissionHandlingEndpoint(String basePath, MeshAuthChain chain, LocalConfigApi localConfigApi, Database db, MeshOptions options) {
super(basePath, chain, localConfigApi, db, options);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import static io.vertx.core.http.HttpMethod.GET;
import static io.vertx.core.http.HttpMethod.POST;

import com.gentics.mesh.auth.MeshAuthChainImpl;
import com.gentics.mesh.auth.MeshAuthChain;
import com.gentics.mesh.cli.BootstrapInitializer;
import com.gentics.mesh.context.InternalActionContext;
import com.gentics.mesh.core.db.Database;
Expand All @@ -22,7 +22,7 @@
*/
public abstract class RolePermissionHandlingProjectEndpoint extends AbstractProjectEndpoint {

protected RolePermissionHandlingProjectEndpoint(String basePath, MeshAuthChainImpl chain,
protected RolePermissionHandlingProjectEndpoint(String basePath, MeshAuthChain chain,
BootstrapInitializer boot, LocalConfigApi localConfigApi, Database db, MeshOptions options) {
super(basePath, chain, boot, localConfigApi, db, options);
}
Expand Down
Loading