private File getDefaultBundle() { return new File(new File(env.getInstanceRoot(), "sync"), getDefaultBundleName()); }
@Override public void execute(AdminCommandContext context) { report = context.getActionReport(); report.setActionExitCode(ExitCode.SUCCESS); logger = context.getLogger(); // we use our own private payload. Don't use the one in the context! payload = PayloadImpl.Outbound.newInstance(); try { if (!isValid()) return; if (!setSyncBundleExportFile()) return; syncRequest = new SyncRequest(); syncRequest.instance = cluster_instance; if (!sync()) return; // write to the das or temp file write(); //all OK...download local file if (isRetrieve) pumpItOut(context); } catch (Exception e) { setError(Strings.get("export.sync.bundle.fail", e.toString())); logger.log(Level.SEVERE, Strings.get("export.sync.bundle.fail", e.toString()), e); return; } }
private boolean setSyncBundleExportFile() { if (isRetrieve) { try { syncBundleExport = File.createTempFile("GlassFishSyncBundle", ".zip"); syncBundleExport.deleteOnExit(); } catch (Exception ex) { syncBundleExport = null; setError(Strings.get("sync.bad_temp_file", ex.getLocalizedMessage())); return false; } } else { File f = null; if (file_name != null && !file_name.isEmpty()) { f = new File(file_name); if (f.isDirectory()) { //Existing directory specified, <target>-sync-bundle.zip is created in specified directory. f = new File(f, getDefaultBundleName()); } } else { //No operand specified, <target>-sync-bundle.zip is created in install-root/domains/domain_name/sync f = getDefaultBundle(); } if (f.getParentFile() != null && !f.getParentFile().exists()) { f.getParentFile().mkdirs(); } syncBundleExport = SmartFile.sanitize(f); } return true; }
private void pumpItOut(AdminCommandContext context) { String fileName = file_name != null && !file_name.isEmpty() ? file_name : getDefaultBundleName(); File localFile = new File(fileName.replace('\\', '/')); Properties props = new Properties(); File parent = localFile.getParentFile(); if (parent == null) { parent = localFile; } props.setProperty("file-xfer-root", parent.getPath().replace('\\', '/')); URI parentURI = parent.toURI(); try { context.getOutboundPayload().attachFile( "application/octet-stream", parentURI.relativize(localFile.toURI()), "sync-bundle", props, syncBundleExport); } catch (IOException ex) { setError(Strings.get("export.sync.bundle.retrieveFailed", ex.getLocalizedMessage())); logger.finer("fileURI: " + parentURI.relativize(localFile.toURI())); logger.finer("file-xfer-root: " + parent.getPath().replace('\\', '/')); logger.finer("file: " + syncBundleExport.getAbsolutePath()); } }
private void write() { OutputStream out = null; try { out = new BufferedOutputStream(new FileOutputStream(syncBundleExport)); payload.writeTo(out); } catch (IOException ex) { setError(Strings.get("export.sync.bundle.exportFailed", syncBundleExport.getAbsolutePath(), ex.getLocalizedMessage())); } finally { if (out != null) { try { out.close(); } catch (IOException ex) { logger.warning(Strings.get("export.sync.bundle.closeStreamFailed", syncBundleExport.getAbsolutePath(), ex.getLocalizedMessage())); } } } if (!isRetrieve) { if (syncBundleExport.isFile()) { report.setMessage(Strings.get("export.sync.bundle.success", syncBundleExport.getAbsolutePath())); } else { setError(Strings.get("export.sync.bundle.fail", syncBundleExport.getAbsolutePath())); } } }
private boolean syncOne() { if (instance != null) { serverSynchronizer.synchronize(instance, syncRequest, payload, report, logger); } if (cluster != null) { // Use one of the clustered instances List<Server> slist = cluster.getInstances(); if (slist != null && !slist.isEmpty()) { Server s = slist.get(0); serverSynchronizer.synchronize(s, syncRequest, payload, report, logger); } } // synchronize() will be set to FAILURE if there were problems return !hasError(); }
@Override public void execute(AdminCommandContext context) { report = context.getActionReport(); report.setActionExitCode(ExitCode.SUCCESS); logger = context.getLogger(); // we use our own private payload. Don't use the one in the context! payload = PayloadImpl.Outbound.newInstance(); try { if (!isValid()) return; if (!setSyncBundleExportFile()) return; syncRequest = new SyncRequest(); syncRequest.instance = cluster_instance; if (!sync()) return; // write to the das or temp file write(); //all OK...download local file if (isRetrieve) pumpItOut(context); } catch (Exception e) { setError(Strings.get("export.sync.bundle.fail", e.toString())); logger.log(Level.SEVERE, Strings.get("export.sync.bundle.fail", e.toString()), e); return; } }
} catch (Exception ex) { syncBundleExport = null; setError(Strings.get("sync.bad_temp_file", ex.getLocalizedMessage())); return false; if (f.isDirectory()) { f = new File(f, getDefaultBundleName()); f = getDefaultBundle(); setError(Strings.get("export.sync.bundle.createDirFailed", f.getParentFile().getPath())); return false;
private void pumpItOut(AdminCommandContext context) { String fileName = file_name != null && !file_name.isEmpty() ? file_name : getDefaultBundleName(); File localFile = new File(fileName.replace('\\', '/')); Properties props = new Properties(); File parent = localFile.getParentFile(); if (parent == null) { parent = localFile; } props.setProperty("file-xfer-root", parent.getPath().replace('\\', '/')); URI parentURI = parent.toURI(); try { context.getOutboundPayload().attachFile( "application/octet-stream", parentURI.relativize(localFile.toURI()), "sync-bundle", props, syncBundleExport); } catch (IOException ex) { setError(Strings.get("export.sync.bundle.retrieveFailed", ex.getLocalizedMessage())); if (logger.isLoggable(Level.FINER)) { logger.finer("fileURI: " + parentURI.relativize(localFile.toURI())); logger.finer("file-xfer-root: " + parent.getPath().replace('\\', '/')); logger.finer("file: " + syncBundleExport.getAbsolutePath()); } } }
private void write() { OutputStream out = null; try { out = new BufferedOutputStream(new FileOutputStream(syncBundleExport)); payload.writeTo(out); } catch (IOException ex) { setError(Strings.get("export.sync.bundle.exportFailed", syncBundleExport.getAbsolutePath(), ex.getLocalizedMessage())); } finally { if (out != null) { try { out.close(); } catch (IOException ex) { logger.warning(Strings.get("export.sync.bundle.closeStreamFailed", syncBundleExport.getAbsolutePath(), ex.getLocalizedMessage())); } } } if (!isRetrieve) { if (syncBundleExport.isFile()) { report.setMessage(Strings.get("export.sync.bundle.success", syncBundleExport.getAbsolutePath())); } else { setError(Strings.get("export.sync.bundle.fail", syncBundleExport.getAbsolutePath())); } } }
private boolean syncOne() { if (instance != null) { serverSynchronizer.synchronize(instance, syncRequest, payload, report, logger); } if (cluster != null) { // Use one of the clustered instances List<Server> slist = cluster.getInstances(); if (slist != null && !slist.isEmpty()) { Server s = slist.get(0); serverSynchronizer.synchronize(s, syncRequest, payload, report, logger); } } // synchronize() will be set to FAILURE if there were problems return !hasError(); }
private boolean isValid() { // verify the cluster or stand-alone server name corresponds to reality! if (servers != null) instance = servers.getServer(cluster_instance); if (clusters != null) { cluster = clusters.getCluster(cluster_instance); if (cluster != null) { List<Server> list = cluster.getInstances(); if (list == null || list.isEmpty()) { setError(Strings.get("sync.empty_cluster", cluster_instance)); return false; } } } if (instance == null && cluster == null) { setError(Strings.get("sync.unknown.instanceOrCluster", cluster_instance)); return false; } return true; }
private File getDefaultBundle() { return new File(new File(env.getInstanceRoot(), "sync"), getDefaultBundleName()); }
private boolean isValid() { // verify the cluster or stand-alone server name corresponds to reality! if (servers != null) instance = servers.getServer(cluster_instance); if (clusters != null) { cluster = clusters.getCluster(cluster_instance); if (cluster != null) { List<Server> list = cluster.getInstances(); if (list == null || list.isEmpty()) { setError(Strings.get("sync.empty_cluster", cluster_instance)); return false; } } } if (instance == null && cluster == null) { setError(Strings.get("sync.unknown.instanceOrCluster", cluster_instance)); return false; } return true; }