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

Faster amps install #1280

Merged
merged 1 commit into from
Aug 21, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,20 @@
import com.marklogic.appdeployer.command.CommandContext;
import com.marklogic.appdeployer.command.security.DeployAmpsCommand;
import com.marklogic.appdeployer.command.security.DeployRolesCommand;
import com.marklogic.client.DatabaseClient;
import com.marklogic.client.DatabaseClientFactory;
import com.marklogic.client.eval.ServerEvaluationCall;
import com.marklogic.client.io.InputStreamHandle;
import com.marklogic.hub.DatabaseKind;
import com.marklogic.hub.HubConfig;
import com.marklogic.hub.deploy.AmpsInstaller;
import com.marklogic.hub.error.DataHubConfigurationException;
import com.marklogic.mgmt.ManageConfig;
import org.springframework.core.io.ClassPathResource;

import java.io.File;
import java.io.IOException;
import java.io.InputStream;

public class DeployHubAmpsCommand extends DeployAmpsCommand {

Expand All @@ -31,11 +42,53 @@ public DeployHubAmpsCommand(HubConfig hubConfig) {
this.hubConfig = hubConfig;
}

@Override
public void execute(CommandContext context) {
String stagingModulesDatabaseName = hubConfig.getStagingAppConfig().getModulesDatabaseName();
ManageConfig manageConfig = context.getManageClient().getManageConfig();
String securityUsername = manageConfig.getSecurityUsername();
String securityPassword = manageConfig.getSecurityPassword();
DatabaseClient installerClient = DatabaseClientFactory.newClient(
hubConfig.getHost(),
8000,
"Security",
new DatabaseClientFactory.DigestAuthContext(securityUsername, securityPassword)
);
//new AmpsInstaller(securityStagingClient).installAmps(stagingModulesDatabaseName);
Copy link
Contributor

@srinathgit srinathgit Aug 20, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@grechaw ,

I think here it is assumed that "App-Services" is set to "digest" auth. In case if all servers were set to cert-auth, digest with ssl or other authentication type, this may not work. I see the same in undo() method as well

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I know -- I was hoping I could ask you how to generalize.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we can use a method like newInstallerClient() in DeployHubAmpsCommand but that would mean that 'sslContext' for stagingAppConfig has to be set to the one obtained using 'admin' certificate (cert whose common name is 'admin' or the security user , user will be logged as the security user). Is that an acceptable change ?

    private DatabaseClient newInstallerClient() {
    	ManageConfig manageConfig = ((HubConfigImpl)hubConfig).getManageConfig();
    	AppConfig stagingAppConfig = hubConfig.getStagingAppConfig();
    	DatabaseClientConfig config = new DatabaseClientConfig(hubConfig.getHost(), 8000, manageConfig.getSecurityUsername(), manageConfig.getSecurityPassword());
	    config.setCertFile(stagingAppConfig.getAppServicesCertFile());
	    config.setCertPassword(stagingAppConfig.getAppServicesCertPassword());
	    config.setDatabase("Security");
	    config.setExternalName(stagingAppConfig.getAppServicesExternalName());
	    config.setSecurityContextType(stagingAppConfig.getAppServicesSecurityContextType());
	    config.setSslContext(stagingAppConfig.getAppServicesSslContext());
	    config.setSslHostnameVerifier(stagingAppConfig.getAppServicesSslHostnameVerifier());
	    config.setTrustManager(stagingAppConfig.getAppServicesTrustManager());
	    return configuredDatabaseClientFactory.newDatabaseClient(config);
    }

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks @srinathgit that's exactly what i needed. I'll take it for a spin

Copy link
Contributor

@srinathgit srinathgit Aug 20, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok ... One thing I noticed with using this newInstallerClient() method is that, if all the servers (App-Services, Manage and Admin) are set to cert-auth, setting stagingAppConfig 's 'sslContext' to the one obtained from certificate whose common name matches 'securityUser' results in LoadModulesCommand, DeleteModulesCommand, GenerateModelArtifactsCommand and LoadSchemasCommand (and maybe some other command ?)running as 'securityUser' and not as 'hub-admin-user' as intended.

ServerEvaluationCall call = installerClient.newServerEval();
try (InputStream is = new ClassPathResource("installer-util/install-amps.xqy").getInputStream()) {
call.xquery( new InputStreamHandle(is));
} catch (IOException e) {
throw new DataHubConfigurationException(e);
}
call.eval();
}

@Override
public void undo(CommandContext context) {
String stagingModulesDatabaseName = hubConfig.getStagingAppConfig().getModulesDatabaseName();
ManageConfig manageConfig = context.getManageClient().getManageConfig();
String securityUsername = manageConfig.getSecurityUsername();
String securityPassword = manageConfig.getSecurityPassword();
DatabaseClient installerClient = DatabaseClientFactory.newClient(
hubConfig.getHost(),
8000,
"Security",
new DatabaseClientFactory.DigestAuthContext(securityUsername, securityPassword)
);
//new AmpsInstaller(securityStagingClient).unInstallAmps(stagingModulesDatabaseName);
ServerEvaluationCall call = installerClient.newServerEval();
try (InputStream is = new ClassPathResource("installer-util/uninstall-amps.xqy").getInputStream()) {
call.xquery(new InputStreamHandle(is));
call.eval();
} catch (IOException e) {
throw new DataHubConfigurationException(e);
}
}

@Override
protected File[] getResourceDirs(CommandContext context) {
return new File[] {
hubConfig.getHubSecurityDir().resolve("amps").toFile(),
hubConfig.getUserSecurityDir().resolve("amps").toFile()
};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -386,7 +386,6 @@ public void installStaging(HubDeployStatusListener listener) {
HubAppDeployer stagingDeployer = new HubAppDeployer(getManageClient(), getAdminManager(), listener, hubConfig.newFinalAppserverClient());
stagingDeployer.setCommands(getStagingCommandList());
stagingDeployer.deploy(stagingConfig);

}

@Override public void updateIndexes() {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
xquery version "1.0-ml";

import module namespace sec="http://marklogic.com/xdmp/security"
at "/MarkLogic/security.xqy";

declare variable $modules-db-name := xdmp:database("data-hub-staging-MODULES");

sec:create-amp("", "addResponseHeader", "/data-hub/4/rest-api/lib/endpoint-util.sjs", $modules-db-name, ("rest-reader-internal")),
sec:create-amp("http://marklogic.com/rest-api/lib/db-util", "access-config", "/data-hub/4/rest-api/lib/db-util.xqy", $modules-db-name, ("rest-reader-internal")),
sec:create-amp("http://marklogic.com/rest-api/lib/db-util", "update-config", "/data-hub/4/rest-api/lib/db-util.xqy", $modules-db-name, ("rest-admin-internal")),
sec:create-amp("http://marklogic.com/rest-api/lib/db-util", "rest-modules-database", "/data-hub/4/rest-api/lib/db-util.xqy", $modules-db-name, ("rest-admin-internal")),
sec:create-amp("http://marklogic.com/rest-api/lib/db-util", "do-set-transaction-time-limit", "/data-hub/4/rest-api/lib/db-util.xqy", $modules-db-name, ("rest-writer-internal")),
sec:create-amp("http://marklogic.com/rest-api/lib/endpoint-util", "add-cookie", "/data-hub/4/rest-api/lib/endpoint-util.xqy", $modules-db-name, ("rest-reader-internal")),
sec:create-amp("http://marklogic.com/rest-api/lib/endpoint-util", "add-response-header", "/data-hub/4/rest-api/lib/endpoint-util.xqy", $modules-db-name, ("rest-reader-internal")),
sec:create-amp("http://marklogic.com/rest-api/lib/endpoint-util", "default-page-with-transform", "/data-hub/4/rest-api/lib/endpoint-util.xqy", $modules-db-name, ("rest-reader-internal")),
sec:create-amp("http://marklogic.com/rest-api/lib/endpoint-util", "delete-cookie", "/data-hub/4/rest-api/lib/endpoint-util.xqy", $modules-db-name, ("rest-reader-internal")),
sec:create-amp("http://marklogic.com/rest-api/lib/endpoint-util", "get-mimetypes", "/data-hub/4/rest-api/lib/endpoint-util.xqy", $modules-db-name, ("rest-reader-internal")),
sec:create-amp("http://marklogic.com/rest-api/lib/endpoint-util", "get-server-field", "/data-hub/4/rest-api/lib/endpoint-util.xqy", $modules-db-name, ("rest-reader-internal")),
sec:create-amp("http://marklogic.com/rest-api/lib/endpoint-util", "invoke-module", "/data-hub/4/rest-api/lib/endpoint-util.xqy", $modules-db-name, ("rest-reader-internal")),
sec:create-amp("http://marklogic.com/rest-api/lib/endpoint-util", "set-server-field", "/data-hub/4/rest-api/lib/endpoint-util.xqy", $modules-db-name, ("rest-reader-internal")),
sec:create-amp("http://marklogic.com/rest-api/lib/endpoint-util", "xslt-invoke", "/data-hub/4/rest-api/lib/endpoint-util.xqy", $modules-db-name, ("rest-reader-internal")),
sec:create-amp("http://marklogic.com/rest-api/lib/endpoint-util", "lookup-role-ids", "/data-hub/4/rest-api/lib/endpoint-util.xqy", $modules-db-name, ("rest-reader-internal")),
sec:create-amp("http://marklogic.com/rest-api/models/document-model-common", "read-collections", "/data-hub/4/rest-api/models/document-model-common.xqy", $modules-db-name, ("rest-reader-internal")),
sec:create-amp("http://marklogic.com/rest-api/models/document-model-common", "read-permissions", "/data-hub/4/rest-api/models/document-model-common.xqy", $modules-db-name, ("rest-reader-internal")),
sec:create-amp("http://marklogic.com/rest-api/models/document-model-common", "read-properties", "/data-hub/4/rest-api/models/document-model-common.xqy", $modules-db-name, ("rest-reader-internal")),
sec:create-amp("http://marklogic.com/rest-api/models/document-model-common", "read-quality", "/data-hub/4/rest-api/models/document-model-common.xqy", $modules-db-name, ("rest-reader-internal")),
sec:create-amp("http://marklogic.com/rest-api/models/document-model-common", "lookup-role-names", "/data-hub/4/rest-api/models/document-model-common.xqy", $modules-db-name, ("rest-reader-internal")),
sec:create-amp("http://marklogic.com/rest-api/models/document-model-query", "get", "/data-hub/4/rest-api/models/document-model-query.xqy", $modules-db-name, ("rest-reader-internal")),
sec:create-amp("http://marklogic.com/rest-api/models/document-model-query-get", "get", "/data-hub/4/rest-api/models/document-model-query-get.xqy", $modules-db-name, ("rest-reader-internal")),
sec:create-amp("http://marklogic.com/rest-api/models/document-model-query-head", "head", "/data-hub/4/rest-api/models/document-model-query-head.xqy", $modules-db-name, ("rest-reader-internal")),
sec:create-amp("http://marklogic.com/rest-api/models/document-model-query", "read-content", "/data-hub/4/rest-api/models/document-model-query.xqy", $modules-db-name, ("rest-reader-internal")),
sec:create-amp("http://marklogic.com/rest-api/models/document-model-query", "check-document-exists", "/data-hub/4/rest-api/models/document-model-query.xqy", $modules-db-name, ("rest-reader-internal")),
sec:create-amp("http://marklogic.com/rest-api/models/document-model-update", "put", "/data-hub/4/rest-api/models/document-model-update.xqy", $modules-db-name, ("rest-writer-internal")),
sec:create-amp("http://marklogic.com/rest-api/models/document-model-update-put", "put", "/data-hub/4/rest-api/models/document-model-update-put.xqy", $modules-db-name, ("rest-writer-internal")),
sec:create-amp("http://marklogic.com/rest-api/models/document-model-update-delete", "delete", "/data-hub/4/rest-api/models/document-model-update-delete.xqy", $modules-db-name, ("rest-writer-internal")),
sec:create-amp("http://marklogic.com/rest-api/models/document-model-update", "patch", "/data-hub/4/rest-api/models/document-model-update.xqy", $modules-db-name, ("rest-writer-internal")),
sec:create-amp("http://marklogic.com/rest-api/models/document-model-update", "delete", "/data-hub/4/rest-api/models/document-model-update.xqy", $modules-db-name, ("rest-writer-internal")),
sec:create-amp("http://marklogic.com/rest-api/models/document-model-update", "apply-content-patch", "/data-hub/4/rest-api/models/document-model-update.xqy", $modules-db-name, ("rest-writer-internal")),
sec:create-amp("http://marklogic.com/rest-api/models/document-model-update", "apply-metadata-patch", "/data-hub/4/rest-api/models/document-model-update.xqy", $modules-db-name, ("rest-writer-internal")),
sec:create-amp("http://marklogic.com/rest-api/models/document-model-update", "delete-document", "/data-hub/4/rest-api/models/document-model-update.xqy", $modules-db-name, ("rest-writer-internal")),
sec:create-amp("http://marklogic.com/rest-api/models/document-model-update", "write-content", "/data-hub/4/rest-api/models/document-model-update.xqy", $modules-db-name, ("rest-writer-internal")),
sec:create-amp("http://marklogic.com/rest-api/models/document-model-update", "load-content", "/data-hub/4/rest-api/models/document-model-update.xqy", $modules-db-name, ("rest-writer-internal")),
sec:create-amp("http://marklogic.com/rest-api/models/document-model-update", "write-collections", "/data-hub/4/rest-api/models/document-model-update.xqy", $modules-db-name, ("rest-writer-internal")),
sec:create-amp("http://marklogic.com/rest-api/models/document-model-update", "write-permissions", "/data-hub/4/rest-api/models/document-model-update.xqy", $modules-db-name, ("rest-writer-internal")),
sec:create-amp("http://marklogic.com/rest-api/models/document-model-update", "write-properties", "/data-hub/4/rest-api/models/document-model-update.xqy", $modules-db-name, ("rest-writer-internal")),
sec:create-amp("http://marklogic.com/rest-api/models/document-model-update", "write-quality", "/data-hub/4/rest-api/models/document-model-update.xqy", $modules-db-name, ("rest-writer-internal")),
sec:create-amp("http://marklogic.com/rest-api/models/document-model-update", "replace-role-permissions", "/data-hub/4/rest-api/models/document-model-update.xqy", $modules-db-name, ("rest-writer-internal")),
sec:create-amp("http://marklogic.com/rest-api/models/document-model-update", "replace-named-properties", "/data-hub/4/rest-api/models/document-model-update.xqy", $modules-db-name, ("rest-writer-internal")),
sec:create-amp("http://marklogic.com/rest-api/models/document-model-update", "remove-collections", "/data-hub/4/rest-api/models/document-model-update.xqy", $modules-db-name, ("rest-writer-internal")),
sec:create-amp("http://marklogic.com/rest-api/models/document-model-update", "reset-permissions", "/data-hub/4/rest-api/models/document-model-update.xqy", $modules-db-name, ("rest-writer-internal")),
sec:create-amp("http://marklogic.com/rest-api/models/document-model-update", "remove-properties", "/data-hub/4/rest-api/models/document-model-update.xqy", $modules-db-name, ("rest-writer-internal")),
sec:create-amp("http://marklogic.com/rest-api/models/document-model-update", "reset-quality", "/data-hub/4/rest-api/models/document-model-update.xqy", $modules-db-name, ("rest-writer-internal")),
sec:create-amp("http://marklogic.com/rest-api/models/document-model-update", "cpf-config", "/data-hub/4/rest-api/models/document-model-update.xqy", $modules-db-name, ("manage-internal")),
sec:create-amp("http://marklogic.com/rest-api/forestinfo", "get-forest-info", "/data-hub/4/rest-api/models/forest-info-model.xqy", $modules-db-name, ("rest-reader-internal")),
sec:create-amp("http://marklogic.com/rest-api/models/search-model-update", "delete", "/data-hub/4/rest-api/models/search-model-update.xqy", $modules-db-name, ("rest-writer-internal")),
sec:create-amp("http://marklogic.com/rest-api/models/search-model-update", "clear", "/data-hub/4/rest-api/models/search-model-update.xqy", $modules-db-name, ("rest-admin-internal")),
sec:create-amp("http://marklogic.com/rest-api/lib/extensions-util", "do-directory-delete", "/data-hub/4/rest-api/lib/extensions-util.xqy", $modules-db-name, ("rest-admin-internal")),
sec:create-amp("http://marklogic.com/rest-api/lib/extensions-util", "do-document-delete", "/data-hub/4/rest-api/lib/extensions-util.xqy", $modules-db-name, ("rest-admin-internal")),
sec:create-amp("http://marklogic.com/rest-api/lib/extensions-util", "do-document-insert", "/data-hub/4/rest-api/lib/extensions-util.xqy", $modules-db-name, ("rest-admin-internal")),
sec:create-amp("http://marklogic.com/rest-api/lib/extensions-util", "do-eval", "/data-hub/4/rest-api/lib/extensions-util.xqy", $modules-db-name, ("rest-admin-internal")),
sec:create-amp("http://marklogic.com/rest-api/lib/extensions-util", "do-js-eval", "/data-hub/4/rest-api/lib/extensions-util.xqy", $modules-db-name, ("rest-admin-internal")),
sec:create-amp("http://marklogic.com/rest-api/lib/extensions-util", "do-list-extension-metadata", "/data-hub/4/rest-api/lib/extensions-util.xqy", $modules-db-name, ("rest-admin-internal")),
sec:create-amp("http://marklogic.com/rest-api/lib/extensions-util", "execute-transform", "/data-hub/4/rest-api/lib/extensions-util.xqy", $modules-db-name, ("rest-admin-internal")),
sec:create-amp("http://marklogic.com/rest-api/lib/extensions-util", "invoke-service", "/data-hub/4/rest-api/lib/extensions-util.xqy", $modules-db-name, ("rest-reader-internal"))
Loading