use of com.centurylink.mdw.designer.utils.RestfulServer in project mdw-designer by CenturyLinkCloud.
the class ProcessExplorerActionGroup method createRunTestsAction.
private IAction createRunTestsAction() {
IAction action = new Action() {
@Override
public void run() {
if (!runTestsApplies(getSelection()))
return;
try {
WorkflowElement element = (WorkflowElement) getSelection().getFirstElement();
WorkflowProject project = element.getProject();
restServer = ((RestfulServer) project.getDesignerDataAccess().getCurrentServer());
restServer.getAppSummary();
refreshRolePermissions(project);
if (!isAuthorized(element)) {
MessageDialog.openError(getViewSite().getShell(), RUN_ACTION, "You are not authorized to run " + element.getName());
return;
}
view.setFocus();
actionHandler.test(getSelection());
} catch (ConnectException ex) {
PluginMessages.log(ex);
MessageDialog.openError(MdwPlugin.getShell(), RUN_ACTION, "Server appears to be offline: " + restServer.getServerUrl());
} catch (Exception ex) {
PluginMessages.log(ex);
MessageDialog.openError(MdwPlugin.getShell(), RUN_ACTION, ex.getMessage());
}
}
};
ImageDescriptor imageDesc = MdwPlugin.getImageDescriptor("icons/testrun.gif");
action.setImageDescriptor(imageDesc);
action.setId(MdwMenuManager.MDW_MENU_PREFIX + "run.tests");
action.setText("Run Tests...");
return action;
}
use of com.centurylink.mdw.designer.utils.RestfulServer in project mdw-designer by CenturyLinkCloud.
the class ProcessExplorerActionGroup method createRunAction.
private IAction createRunAction() {
IAction action = new Action() {
@Override
public void run() {
if (!runApplies(getSelection()))
return;
try {
WorkflowElement element = (WorkflowElement) getSelection().getFirstElement();
WorkflowProject project = element.getProject();
restServer = ((RestfulServer) project.getDesignerDataAccess().getCurrentServer());
restServer.getAppSummary();
refreshRolePermissions(project);
if (!isAuthorized(element)) {
MessageDialog.openError(getViewSite().getShell(), RUN_ACTION, "You are not authorized to run " + element.getName());
return;
}
view.setFocus();
if (element instanceof AutomatedTestSuite || element instanceof AutomatedTestCase)
actionHandler.test(getSelection());
else
actionHandler.run((WorkflowElement) element);
} catch (ConnectException ex) {
PluginMessages.log(ex);
MessageDialog.openError(MdwPlugin.getShell(), RUN_ACTION, "Server appears to be offline: " + restServer.getServerUrl());
} catch (Exception ex) {
PluginMessages.log(ex);
MessageDialog.openError(MdwPlugin.getShell(), RUN_ACTION, ex.getMessage());
}
}
};
ImageDescriptor imageDesc = MdwPlugin.getImageDescriptor(ICON_RUN_GIF);
action.setImageDescriptor(imageDesc);
action.setId(MdwMenuManager.MDW_MENU_PREFIX + "run");
action.setText("Run...");
return action;
}
use of com.centurylink.mdw.designer.utils.RestfulServer in project mdw-designer by CenturyLinkCloud.
the class WorkflowProject method getMdwVersion.
/**
* Also populates appVersion to avoid two server calls if first one fails.
* Does not attempt to populate if not initialized (ie not expanded in proc
* exp view).
*/
public String getMdwVersion() {
if (isRemote() && mdwVersion == null && designerProxy != null) {
mdwVersion = "Unknown";
appVersion = "Unknown";
AppSummary appSummary = getRemoteAppSummary(false);
if (appSummary != null && appSummary.getMdwVersion() != null) {
mdwVersion = appSummary.getMdwVersion();
appVersion = appSummary.getAppVersion();
try {
// force parse (triggering exception for unparseable -- eg:
// @mdw.version@)
MdwVersion vers = new MdwVersion(mdwVersion);
vers.getMajorVersion();
vers.getMinorVersion();
vers.getBuildId();
} catch (Exception ex) {
mdwVersion = "Unknown";
PluginMessages.log(ex);
}
} else {
if (isFilePersist()) {
// minimum supported version (TODO:
mdwVersion = "5.5";
// future versions)
} else {
// server may not be running -- infer version from db
// structure
String jdbcUrl = getMdwDataSource().getJdbcUrlWithCredentials();
if (jdbcUrl != null) {
try {
// don't initialize designerProxy just to infer
// version from db
RestfulServer server = new RestfulServer(jdbcUrl, getUser().getUsername(), getServiceUrl());
DesignerDataAccess dao = new DesignerDataAccess(server, new ArrayList<Server>(), getUser().getUsername());
int dbSchemaVersion = dao.getDatabaseSchemaVersion();
int major = dbSchemaVersion / 1000;
int minor = dbSchemaVersion % 1000;
mdwVersion = major + "." + minor;
} catch (Exception ex) {
// dataAccessFailed
PluginMessages.log(ex);
}
}
}
}
}
return mdwVersion;
}
use of com.centurylink.mdw.designer.utils.RestfulServer in project mdw-designer by CenturyLinkCloud.
the class DesignerProxy method initialize.
public void initialize(ProgressMonitor progressMonitor) throws Exception {
mainFrame = new MainFrame("Not Displayed");
mainFrame.setOptionPane(new SwtDialogProvider(MdwPlugin.getDisplay()));
CodeTimer timer = new CodeTimer("initialize()");
Map<String, String> connProps = new HashMap<>();
try {
User user = project.getUser();
if (user != null && user.getJwtToken() != null)
user.setJwtToken(((MdwAuthenticator) project.getAuthenticator()).doAuthentication(user.getUsername(), user.getPassword()));
if (user == null)
handleLazyUserAuth();
if (project.getPersistType() == WorkflowProject.PersistType.Git) {
restfulServer = createRestfulServer(project.getMdwDataSource().getJdbcUrlWithCredentials(), project.getMdwMajorVersion() * 1000 + project.getMdwMinorVersion() * 100);
VcsRepository gitRepo = project.getMdwVcsRepository();
VersionControlGit versionControl = new VersionControlGit();
String gitUser = null;
String gitPassword = null;
if (MdwPlugin.getSettings().isUseDiscoveredVcsCredentials()) {
gitUser = gitRepo.getUser();
gitPassword = gitRepo.getPassword();
}
versionControl.connect(gitRepo.getRepositoryUrl(), gitUser, gitPassword, project.getProjectDir());
versionControl.setValidateVersions(!project.checkRequiredVersion(6) && MdwPlugin.getSettings().isValidateProcessVersions());
restfulServer.setVersionControl(versionControl);
restfulServer.setRootDirectory(project.getAssetDir());
if (project.isRemote()) {
File assetDir = project.getAssetDir();
boolean isGit = gitRepo.getRepositoryUrl() != null;
String pkgDownloadServicePath = null;
try {
if (isGit) {
// update branch from Git
if (progressMonitor != null)
progressMonitor.subTask("Retrieving Git status");
// avoid
Platform.getBundle("org.eclipse.egit.ui").start();
// Eclipse
// default
// Authenticator
// --
// otherwise
// login
// fails
AppSummary appSummary = restfulServer.getAppSummary();
if (appSummary.getRepository() == null)
throw new DataAccessOfflineException("Unable to confirm Git status on server (missing repository)");
String branch = appSummary.getRepository().getBranch();
if (branch == null || branch.isEmpty())
throw new DataAccessOfflineException("Unable to confirm Git status on server (missing branch)");
String oldBranch = gitRepo.getBranch();
if (!branch.equals(oldBranch))
gitRepo.setBranch(branch);
if (progressMonitor != null)
progressMonitor.subTask("Updating from branch: " + branch);
versionControl.hardReset();
// in case changed
versionControl.checkout(branch);
versionControl.pull(branch);
String serverCommit = appSummary.getRepository().getCommit();
String localCommit = versionControl.getCommit();
if (localCommit == null || !localCommit.equals(serverCommit)) {
project.setWarn(true);
PluginMessages.log("Server commit: " + serverCommit + " does not match Git repository for branch " + branch + ": " + versionControl.getCommit() + ".", IStatus.WARNING);
}
// save
WorkflowProjectManager.getInstance().save(project);
// branch
if (progressMonitor != null)
progressMonitor.progress(10);
if (project.checkRequiredVersion(5, 5, 34))
pkgDownloadServicePath = "Packages?format=json&nonVersioned=true";
} else {
// non-git -- delete existing asset dir
if (assetDir.exists())
PluginUtil.deleteDirectory(assetDir);
if (!assetDir.mkdirs())
throw new DiscoveryException("Unable to create asset directory: " + assetDir);
pkgDownloadServicePath = "Packages?format=json&topLevel=true";
}
if (pkgDownloadServicePath != null && progressMonitor != null) {
if (gitRepo.isSyncAssetArchive())
pkgDownloadServicePath += "&archive=true";
String json = restfulServer.invokeResourceService(pkgDownloadServicePath);
Download download = new Download(new JSONObject(json));
if (!StringHelper.isEmpty(download.getUrl())) {
URL url = new URL(download.getUrl() + "&recursive=true");
IFolder tempFolder = project.getTempFolder();
IFile tempFile = tempFolder.getFile("/pkgs" + StringHelper.filenameDateToString(new Date()) + ".zip");
IProgressMonitor subMonitor = new SubProgressMonitor(((SwtProgressMonitor) progressMonitor).getWrappedMonitor(), 5);
try {
PluginUtil.downloadIntoProject(project.getSourceProject(), url, tempFolder, tempFile, "Download Packages", subMonitor);
PluginUtil.unzipProjectResource(project.getSourceProject(), tempFile, null, project.getAssetFolder(), subMonitor);
} catch (FileNotFoundException ex) {
if (isGit)
PluginMessages.uiMessage("Extra/Archived packages not retrieved. Showing only assets from Git.", "Load Workflow Project", PluginMessages.INFO_MESSAGE);
else
throw ex;
}
}
}
} catch (ZipException ze) {
throw ze;
} catch (IOException ex) {
PluginMessages.uiMessage("Extra/Archived packages not retrieved. Showing only assets from Git.", "Load Workflow Project", PluginMessages.INFO_MESSAGE);
}
}
} else if (project.getPersistType() == WorkflowProject.PersistType.None) {
restfulServer = new RestfulServer(null, project.getUser().getUsername(), project.getServiceUrl());
VersionControl dummyVersionControl = new VersionControlDummy();
dummyVersionControl.connect(null, null, null, project.getProjectDir());
restfulServer.setVersionControl(dummyVersionControl);
restfulServer.setRootDirectory(project.getAssetDir());
} else {
String jdbcUrl = project.getMdwDataSource().getJdbcUrlWithCredentials();
if (jdbcUrl == null)
throw new DataAccessException("Please specify a valid JDBC URL in your MDW Project Settings");
if (project.getMdwDataSource().getSchemaOwner() == null)
// don't qualify queries
DBMappingUtil.setSchemaOwner("");
else
DBMappingUtil.setSchemaOwner(project.getMdwDataSource().getSchemaOwner());
restfulServer = new RestfulServer(jdbcUrl, project.getUser().getUsername(), project.getServiceUrl());
connProps.put("defaultRowPrefetch", String.valueOf(MdwPlugin.getSettings().getJdbcFetchSize()));
}
cacheRefresh = new CacheRefresh(project, restfulServer);
boolean oldNamespaces = project.isOldNamespaces();
boolean remoteRetrieve = project.isFilePersist() && project.checkRequiredVersion(5, 5, 19);
restfulServer.setConnectTimeout(MdwPlugin.getSettings().getHttpConnectTimeout());
restfulServer.setReadTimeout(MdwPlugin.getSettings().getHttpReadTimeout());
mainFrame.startSession(project.getUser().getUsername(), restfulServer, progressMonitor, connProps, oldNamespaces, remoteRetrieve);
restfulServer.setDataModel(mainFrame.getDataModel());
mainFrame.dao.setCurrentServer(restfulServer);
dataAccess = new PluginDataAccess(project, mainFrame.getDataModel(), mainFrame.dao);
// they've already been retrieved
dataAccess.organizeRuleSets();
// static supportedSchemaVersion has just been set, so save it at
// instance level
dataAccess.setSupportedSchemaVersion(DataAccess.supportedSchemaVersion);
if (project.getPersistType() == WorkflowProject.PersistType.Git && !project.isRemote()) {
try {
mainFrame.dao.checkServerOnline();
} catch (DataAccessOfflineException offlineEx) {
if (MdwPlugin.getSettings().isLogConnectErrors())
PluginMessages.log(offlineEx);
}
}
dataAccess.getVariableTypes(true);
try {
// override mainframe's settings for look-and-feel
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
} catch (Exception ex) {
PluginMessages.log(ex);
}
System.setProperty("awt.useSystemAAFontSettings", "on");
System.setProperty("swing.aatext", "true");
} finally {
timer.stopAndLog();
}
}
use of com.centurylink.mdw.designer.utils.RestfulServer in project mdw-designer by CenturyLinkCloud.
the class AutoTestAntTask method execute.
@Override
public void execute() throws BuildException {
try {
if (sslTrustStore != null)
System.setProperty("javax.net.ssl.trustStore", sslTrustStore.getAbsolutePath());
DesignerDataAccess.getAuthenticator().authenticate(user, password);
RestfulServer restfulServer = new RestfulServer(jdbcUrl == null ? "dummy" : jdbcUrl, user, serverUrl.toString());
if (workflowDir != null) {
// vcs-based assets
VersionControl versionControl = new VersionControlGit();
versionControl.connect(null, null, null, workflowDir);
restfulServer.setVersionControl(versionControl);
restfulServer.setRootDirectory(workflowDir);
restfulServer.setDatabaseUrl("jdbc://dummy");
designerDataAccess = new DesignerDataAccess(restfulServer, null, user, false);
designerDataAccess.setCurrentServer(restfulServer);
} else {
designerDataAccess = new DesignerDataAccess(restfulServer, null, user, oldNamespaces);
if (designerDataAccess.getUser(user) == null)
throw new BuildException("User '" + user + "' not found to run automated tests for this environment.");
if (!designerDataAccess.getUser(user).hasRole(UserGroupVO.COMMON_GROUP, UserRoleVO.PROCESS_EXECUTION) && !designerDataAccess.getUser(user).hasRole(UserGroupVO.SITE_ADMIN_GROUP, UserRoleVO.PROCESS_EXECUTION))
throw new BuildException("User '" + user + "' not authorized to run automated tests for this environment.");
}
VariableTypeCache.loadCache(designerDataAccess.getVariableTypes());
log("Setup completed for test suite: '" + suiteName + "'", Project.MSG_ERR);
try {
if (stubbing) {
Stubber stubber = new Stubber() {
public String processMessage(String masterRequestId, String request) {
try {
TestCaseRun run = masterRequestRunMap.get(masterRequestId);
if (run == null) {
JSONObject requestJson = null;
// mdw6
ActivityStubRequest activityStubRequest = null;
ActivityRuntimeContext activityRuntimeContext = null;
// mdw6
AdapterStubRequest adapterStubRequest = null;
if (request != null && request.trim().startsWith("{")) {
try {
requestJson = new JSONObject(request);
} catch (JSONException ex) {
// unparseable -- handle old way for
// adapter stubbing
}
if (requestJson != null) {
if (requestJson.has(ActivityStubRequest.JSON_NAME)) {
activityStubRequest = new ActivityStubRequest(requestJson);
activityRuntimeContext = activityStubRequest.getRuntimeContext();
} else if (requestJson.has("ActivityRuntimeContext")) {
activityRuntimeContext = new ActivityRuntimeContext(requestJson);
} else if (requestJson.has(AdapterStubRequest.JSON_NAME)) {
adapterStubRequest = new AdapterStubRequest(requestJson);
}
}
}
if (activityRuntimeContext != null) {
if (activityStubRequest != null) {
// mdw6+
ActivityStubResponse activityStubResponse = new ActivityStubResponse();
activityStubResponse.setPassthrough(true);
return activityStubResponse.getJson().toString(2);
} else {
return "(EXECUTE_ACTIVITY)";
}
} else {
if (adapterStubRequest != null) {
// mdw6+
AdapterStubResponse stubResponse = new AdapterStubResponse(AdapterActivity.MAKE_ACTUAL_CALL);
stubResponse.setPassthrough(true);
return stubResponse.getJson().toString(2);
} else {
return AdapterActivity.MAKE_ACTUAL_CALL;
}
}
}
return run.getStubResponse(masterRequestId, request, run.getRunNumber());
} catch (Exception ex) {
log(ex.getMessage(), ex, Project.MSG_ERR);
return null;
}
}
};
if (StubServer.isRunning())
StubServer.stop();
StubServer.start(restfulServer, stubPort, stubber, this.oldNamespaces);
}
runTests();
} finally {
// try not to leave the socket connection open
StubServer.stop();
}
} catch (BuildException ex) {
throw ex;
} catch (Exception ex) {
try {
updateResults(true);
} catch (BuildException bex) {
throw bex;
} catch (IOException ioex) {
log(ioex.getMessage(), ioex, Project.MSG_ERR);
}
log(ex.getMessage(), ex, Project.MSG_ERR);
throw new BuildException(ex);
}
}
Aggregations