use of com.centurylink.mdw.dataaccess.file.VersionControlGit in project mdw-designer by CenturyLinkCloud.
the class Exporter method main.
public static void main(String[] args) {
if (args.length == 1 && "-h".equals(args[0])) {
System.out.println("Example Usage: ");
System.out.println("java com.centurylink.mdw.designer.Exporter " + "jdbc:oracle:thin:mdwdemo/mdwdemo@mdwdevdb.dev.qintra.com:1594:mdwdev (or /path/to/root/storage) " + "com.centurylink.mdw.tests " + "/path/to/packageDef(.xml|.json)");
System.exit(0);
}
if (args.length != 2 && args.length != 3) {
System.err.println("arguments: <jdbcUrl|fileBasedRootDir> <packageName> <xmlFile>");
System.err.println("(-h for example usage)");
System.exit(-1);
}
// either jdbcUrl or local file path
String arg0 = args[0];
String packageName = args[1];
String outFile = args[2];
try {
boolean local = !arg0.startsWith("jdbc:");
RestfulServer restfulServer = new RestfulServer(local ? "jdbc://dummy" : arg0, null, "http://dummy");
DesignerDataAccess dataAccess;
if (local) {
VersionControl versionControl = new VersionControlGit();
versionControl.connect(null, null, null, new File(arg0));
restfulServer.setVersionControl(versionControl);
restfulServer.setRootDirectory(new File(arg0));
dataAccess = new DesignerDataAccess(restfulServer, null, EXPORT, false);
} else {
dataAccess = new DesignerDataAccess(restfulServer, null, EXPORT, true);
}
System.out.println("Exporting with arguments: " + arg0 + " " + packageName + " " + outFile);
Exporter exporter = new Exporter(dataAccess);
long before = System.currentTimeMillis();
String xml = exporter.exportPackage(packageName, true, outFile.endsWith(".json"));
File outputFile = new File(outFile);
if (outputFile.exists()) {
System.out.println("Overwriting existing file: " + outputFile);
} else if (!outputFile.getParentFile().exists() && !outputFile.getParentFile().mkdirs()) {
throw new IOException("Cannot create directory: " + outputFile.getParentFile());
}
exporter.writeFile(outputFile, xml.getBytes());
long afterExport = System.currentTimeMillis();
System.out.println("Time taken for export: " + ((afterExport - before) / 1000) + " s");
} catch (Exception ex) {
ex.printStackTrace();
System.exit(-1);
}
}
use of com.centurylink.mdw.dataaccess.file.VersionControlGit in project mdw-designer by CenturyLinkCloud.
the class Importer method main.
public static void main(String[] args) {
if (args.length == 1 && "-h".equals(args[0])) {
System.out.println("Example Usage: ");
System.out.println("java com.centurylink.mdw.designer.Importer appcuid apppassword " + "jdbc:oracle:thin:mdwdemo/mdwdemo@mdwdevdb.dev.qintra.com:1594:mdwdev (or /path/to/root/storage) " + "http://lxdenvmtc143.dev.qintra.com:7021/maven/repository/mdw/com/centurylink/mdw/assets/camel/5.5.11/com.centurylink.mdw.camel-5.5.11.xml " + "overwrite=true");
System.exit(0);
}
if (args.length != 4 && args.length != 5) {
System.err.println("arguments: <user> <password> <jdbcUrl|fileBasedRootDir> <xmlFile|xmlFileUrl> <overwrite=(true|FALSE)>");
System.err.println("(-h for example usage)");
System.exit(-1);
}
String user = args[0];
String password = args[1];
// either jdbcUrl or local file path
String arg2 = args[2];
String xmlFile = args[3];
boolean overwrite = (args.length == 5 && "overwrite=true".equalsIgnoreCase(args[4])) ? true : false;
try {
DesignerDataAccess.getAuthenticator().authenticate(user, password);
boolean local = !arg2.startsWith("jdbc:");
RestfulServer restfulServer = new RestfulServer(local ? "jdbc://dummy" : arg2, user, "http://dummy");
DesignerDataAccess dataAccess;
if (local) {
VersionControl versionControl = new VersionControlGit();
versionControl.connect(null, null, null, new File(arg2));
restfulServer.setVersionControl(versionControl);
restfulServer.setRootDirectory(new File(arg2));
dataAccess = new DesignerDataAccess(restfulServer, null, user, false);
} else {
dataAccess = new DesignerDataAccess(restfulServer, null, user, true);
UserVO userVO = dataAccess.getUser(user);
if (userVO == null)
throw new DataAccessException("User: '" + user + "' not found.");
if (!userVO.hasRole(UserGroupVO.COMMON_GROUP, UserRoleVO.PROCESS_DESIGN))
throw new DataAccessException("User: '" + user + "' not authorized for " + UserRoleVO.PROCESS_DESIGN + ".");
}
String xml;
if ("http://".startsWith(xmlFile) || "https://".startsWith(xmlFile)) {
xml = new HttpHelper(new URL(xmlFile)).get();
} else {
xml = readFile(xmlFile);
}
System.out.println("Importing with arguments: " + user + " ******* " + arg2 + " " + xmlFile);
Importer importer = new Importer(dataAccess);
long before = System.currentTimeMillis();
importer.importPackage(xml, overwrite);
long afterImport = System.currentTimeMillis();
System.out.println("Time taken for import: " + ((afterImport - before) / 1000) + " s");
System.out.println("Please restart your server or refresh the MDW asset cache.");
} catch (Exception ex) {
ex.printStackTrace();
System.exit(-1);
}
}
use of com.centurylink.mdw.dataaccess.file.VersionControlGit in project mdw-designer by CenturyLinkCloud.
the class ImportPackageWizard method unzipToLocal.
void unzipToLocal(WorkflowProject wfp, java.io.File zipFile, java.io.File tempDir, java.io.File assetDir, List<WorkflowPackage> importedPackages, ProgressMonitor progressMonitor) throws IOException, DataAccessException, CoreException, JSONException {
VersionControl vcs = new VersionControlGit();
vcs.connect(null, null, null, wfp.getAssetDir());
progressMonitor.subTask("Archive existing assets...");
VcsArchiver archiver = new VcsArchiver(assetDir, tempDir, vcs, progressMonitor);
archiver.backup();
PluginMessages.log("Unzipping " + zipFile + " into: " + assetDir);
ZipHelper.unzip(zipFile, assetDir, null, null, true);
archiver.archive();
ZipHelper.unzip(zipFile, tempDir, null, null, true);
wfp.getSourceProject().refreshLocal(2, null);
java.io.File explodedDir = new java.io.File(tempDir + "/com");
if (explodedDir.isDirectory()) {
List<java.io.File> fileList = FileHelper.getFilesRecursive(explodedDir, "package.json", new ArrayList<java.io.File>());
for (java.io.File file : fileList) {
WorkflowPackage workflowPackage = new WorkflowPackage();
workflowPackage.setProject(wfp);
workflowPackage.setPackageVO(new PackageVO(new JSONObject(FileHelper.getFileContents(file.getPath()))));
importedPackages.add(workflowPackage);
}
FileHelper.deleteRecursive(explodedDir);
}
}
use of com.centurylink.mdw.dataaccess.file.VersionControlGit in project mdw-designer by CenturyLinkCloud.
the class ImportProjectWizard method performFinish.
@Override
public boolean performFinish() {
if (errorMessage != null) {
MessageDialog.openError(getShell(), "Import Project", errorMessage);
return false;
}
BusyIndicator.showWhile(getShell().getDisplay(), new Runnable() {
public void run() {
List<IProject> existingProjects = new ArrayList<>();
for (WorkflowProject toImport : projectsToImport) {
IProject existing = MdwPlugin.getWorkspaceRoot().getProject(toImport.getName());
if (existing != null && existing.exists())
existingProjects.add(existing);
}
if (!existingProjects.isEmpty()) {
String text = "Please confirm that the following workspace projects should be overwritten:";
ListSelectionDialog lsd = new ListSelectionDialog(getShell(), existingProjects, new ExistingProjectContentProvider(), new ProjectLabelProvider(), text);
lsd.setTitle("Existing Projects");
lsd.setInitialSelections(existingProjects.toArray(new IProject[0]));
lsd.open();
Object[] results = lsd.getResult();
if (results == null) {
cancel = true;
return;
}
for (IProject existing : existingProjects) {
boolean include = false;
for (Object included : results) {
if (existing.getName().equals(((IProject) included).getName()))
include = true;
}
if (include) {
WorkflowProjectManager.getInstance().deleteProject(existing);
} else {
WorkflowProject toRemove = null;
for (WorkflowProject wfp : projectList) {
if (wfp.getName().equals(existing.getName())) {
toRemove = wfp;
break;
}
}
if (toRemove != null)
projectsToImport.remove(toRemove);
}
}
}
}
});
if (cancel)
return false;
if (projectsToImport.isEmpty()) {
MessageDialog.openInformation(getShell(), "Import Projects", "No projects to import.");
return true;
}
try {
getContainer().run(false, false, new IRunnableWithProgress() {
public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
monitor.beginTask("Importing MDW project(s)", 100);
monitor.worked(20);
try {
for (WorkflowProject workflowProject : projectsToImport) {
if (workflowProject.isFilePersist()) {
File projectDir = new File(ResourcesPlugin.getWorkspace().getRoot().getLocation().toFile() + "/" + workflowProject.getName());
projectDir.mkdir();
String repositoryUrl = projectsToImport.get(0).getMdwVcsRepository().getRepositoryUrl();
if (repositoryUrl != null && repositoryUrl.length() > 0) {
// avoid
Platform.getBundle("org.eclipse.egit.ui").start();
// Eclipse
// default
// Authenticator
workflowProject.setPersistType(PersistType.Git);
workflowProject.getMdwVcsRepository().setProvider(VcsRepository.PROVIDER_GIT);
monitor.subTask("Cloning Git repository for " + workflowProject.getLabel());
monitor.worked(1);
VcsRepository gitRepo = workflowProject.getMdwVcsRepository();
VersionControlGit vcsGit = new VersionControlGit();
String user = null;
String password = null;
if (MdwPlugin.getSettings().isUseDiscoveredVcsCredentials()) {
user = gitRepo.getUser();
password = gitRepo.getPassword();
}
vcsGit.connect(gitRepo.getRepositoryUrl(), user, password, projectDir);
vcsGit.cloneRepo();
} else {
File assetDir = new File(projectDir + "/" + workflowProject.getMdwVcsRepository().getLocalPath());
assetDir.mkdirs();
}
monitor.worked(40 / projectsToImport.size());
}
ProjectInflator inflator = new ProjectInflator(workflowProject, MdwPlugin.getSettings());
inflator.inflateRemoteProject(getContainer());
}
} catch (Exception ex) {
throw new InvocationTargetException(ex);
}
ProjectImporter projectImporter = new ProjectImporter(projectsToImport);
projectImporter.doImport();
monitor.worked(20);
monitor.done();
}
});
} catch (Exception ex) {
PluginMessages.uiError(ex, "Import Project");
return false;
}
DesignerPerspective.openPerspective(activeWindow);
return true;
}
use of com.centurylink.mdw.dataaccess.file.VersionControlGit 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();
}
}
Aggregations