Skip to content
Snippets Groups Projects
Commit 41cb1af3 authored by Jan Kožusznik's avatar Jan Kožusznik
Browse files

code: clean up and add debug loging

parent 2d459203
No related branches found
No related tags found
No related merge requests found
package cz.it4i.fiji.haas_java_client; package cz.it4i.fiji.haas_java_client;
import com.jcraft.jsch.JSchException; import com.jcraft.jsch.JSchException;
...@@ -57,50 +58,49 @@ import cz.it4i.fiji.scpclient.TransferFileProgress; ...@@ -57,50 +58,49 @@ import cz.it4i.fiji.scpclient.TransferFileProgress;
public class HaaSClient { public class HaaSClient {
public static final TransferFileProgress DUMMY_TRANSFER_FILE_PROGRESS = new TransferFileProgress() { public static final TransferFileProgress DUMMY_TRANSFER_FILE_PROGRESS =
new TransferFileProgress()
{
@Override @Override
public void dataTransfered(long bytesTransfered) { public void dataTransfered(final long bytesTransfered) {
// TODO Auto-generated method stub // TODO Auto-generated method stub
} }
}; };
public static ProgressNotifier DUMMY_PROGRESS_NOTIFIER = new ProgressNotifier() { public static ProgressNotifier DUMMY_PROGRESS_NOTIFIER =
new ProgressNotifier()
{
@Override @Override
public void setTitle(String title) { public void setTitle(final String title) {}
}
@Override @Override
public void setItemCount(int count, int total) { public void setItemCount(final int count, final int total) {}
}
@Override @Override
public void setCount(int count, int total) { public void setCount(final int count, final int total) {}
}
@Override @Override
public void itemDone(Object item) { public void itemDone(final Object item) {}
}
@Override @Override
public void done() { public void done() {}
}
@Override @Override
public void addItem(Object item) { public void addItem(final Object item) {}
} };
};
public static UploadingFile getUploadingFile(Path file) { public static UploadingFile getUploadingFile(final Path file) {
return new UploadingFile() { return new UploadingFile() {
@Override @Override
public InputStream getInputStream() { public InputStream getInputStream() {
try { try {
return Files.newInputStream(file); return Files.newInputStream(file);
} catch (IOException e) { }
catch (final IOException e) {
log.error(e.getMessage(), e); log.error(e.getMessage(), e);
throw new RuntimeException(e); throw new RuntimeException(e);
} }
...@@ -115,7 +115,8 @@ public class HaaSClient { ...@@ -115,7 +115,8 @@ public class HaaSClient {
public long getLength() { public long getLength() {
try { try {
return Files.size(file); return Files.size(file);
} catch (IOException e) { }
catch (final IOException e) {
log.error(e.getMessage(), e); log.error(e.getMessage(), e);
throw new RuntimeException(e); throw new RuntimeException(e);
} }
...@@ -125,7 +126,8 @@ public class HaaSClient { ...@@ -125,7 +126,8 @@ public class HaaSClient {
public long getLastTime() { public long getLastTime() {
try { try {
return Files.getLastModifiedTime(file).toMillis(); return Files.getLastModifiedTime(file).toMillis();
} catch (IOException e) { }
catch (final IOException e) {
log.error(e.getMessage(), e); log.error(e.getMessage(), e);
throw new RuntimeException(e); throw new RuntimeException(e);
} }
...@@ -138,8 +140,10 @@ public class HaaSClient { ...@@ -138,8 +140,10 @@ public class HaaSClient {
private final Collection<TaskFileOffsetExt> files = new LinkedList<>(); private final Collection<TaskFileOffsetExt> files = new LinkedList<>();
public void addFile(long taskId, SynchronizableFileType type, long offset) { public void addFile(final long taskId, final SynchronizableFileType type,
TaskFileOffsetExt off = new TaskFileOffsetExt(); final long offset)
{
final TaskFileOffsetExt off = new TaskFileOffsetExt();
off.setFileType(getType(type)); off.setFileType(getType(type));
off.setSubmittedTaskInfoId(taskId); off.setSubmittedTaskInfoId(taskId);
off.setOffset(offset); off.setOffset(offset);
...@@ -150,29 +154,30 @@ public class HaaSClient { ...@@ -150,29 +154,30 @@ public class HaaSClient {
return files; return files;
} }
private SynchronizableFilesExt getType(SynchronizableFileType type) { private SynchronizableFilesExt getType(final SynchronizableFileType type) {
switch (type) { switch (type) {
case LogFile: case LogFile:
return SynchronizableFilesExt.LOG_FILE; return SynchronizableFilesExt.LOG_FILE;
case ProgressFile: case ProgressFile:
return SynchronizableFilesExt.PROGRESS_FILE; return SynchronizableFilesExt.PROGRESS_FILE;
case StandardErrorFile: case StandardErrorFile:
return SynchronizableFilesExt.STANDARD_ERROR_FILE; return SynchronizableFilesExt.STANDARD_ERROR_FILE;
case StandardOutputFile: case StandardOutputFile:
return SynchronizableFilesExt.STANDARD_OUTPUT_FILE; return SynchronizableFilesExt.STANDARD_OUTPUT_FILE;
default: default:
throw new UnsupportedOperationException("Unsupported type: " + type); throw new UnsupportedOperationException("Unsupported type: " + type);
} }
} }
} }
private static Logger log = LoggerFactory.getLogger(cz.it4i.fiji.haas_java_client.HaaSClient.class); private static Logger log = LoggerFactory.getLogger(
cz.it4i.fiji.haas_java_client.HaaSClient.class);
final static private Map<JobStateExt, JobState> WS_STATE2STATE; final static private Map<JobStateExt, JobState> WS_STATE2STATE;
static { static {
Map<JobStateExt, JobState> map = new HashMap<>(); final Map<JobStateExt, JobState> map = new HashMap<>();
map.put(JobStateExt.CANCELED, JobState.Canceled); map.put(JobStateExt.CANCELED, JobState.Canceled);
map.put(JobStateExt.CONFIGURING, JobState.Configuring); map.put(JobStateExt.CONFIGURING, JobState.Configuring);
map.put(JobStateExt.FAILED, JobState.Failed); map.put(JobStateExt.FAILED, JobState.Failed);
...@@ -193,41 +198,51 @@ public class HaaSClient { ...@@ -193,41 +198,51 @@ public class HaaSClient {
private final String projectId; private final String projectId;
private final Map<Long, P_FileTransferPool> filetransferPoolMap = new HashMap<>(); private final Map<Long, P_FileTransferPool> filetransferPoolMap =
new HashMap<>();
private final HaaSClientSettings settings; private final HaaSClientSettings settings;
private DataTransferWsSoap dataTransferWs; private DataTransferWsSoap dataTransferWs;
public HaaSClient(final HaaSClientSettings settings) {
public HaaSClient(HaaSClientSettings settings) {
this.settings = settings; this.settings = settings;
this.projectId = settings.getProjectId(); this.projectId = settings.getProjectId();
} }
public long createJob(JobSettings jobSettings, Collection<Entry<String, String>> templateParameters) { public long createJob(final JobSettings jobSettings,
final Collection<Entry<String, String>> templateParameters)
{
return doCreateJob(jobSettings, templateParameters); return doCreateJob(jobSettings, templateParameters);
} }
public HaaSFileTransfer startFileTransfer(long jobId, TransferFileProgress notifier) { public HaaSFileTransfer startFileTransfer(final long jobId,
final TransferFileProgress notifier)
{
try { try {
return createFileTransfer(jobId, notifier); return createFileTransfer(jobId, notifier);
} catch (RemoteException | ServiceException | UnsupportedEncodingException | JSchException e) { }
catch (RemoteException | ServiceException | UnsupportedEncodingException
| JSchException e)
{
throw new HaaSClientException(e); throw new HaaSClientException(e);
} }
} }
public HaaSFileTransfer startFileTransfer(long jobId) { public HaaSFileTransfer startFileTransfer(final long jobId) {
return startFileTransfer(jobId, DUMMY_TRANSFER_FILE_PROGRESS); return startFileTransfer(jobId, DUMMY_TRANSFER_FILE_PROGRESS);
} }
public TunnelToNode openTunnel(long jobId, String nodeIP, int localPort, int remotePort) { public TunnelToNode openTunnel(final long jobId, final String nodeIP,
final int localPort, final int remotePort)
{
MiddlewareTunnel tunnel; MiddlewareTunnel tunnel;
try { try {
tunnel = new MiddlewareTunnel(Executors.newCachedThreadPool(), jobId, nodeIP, getSessionID()); tunnel = new MiddlewareTunnel(Executors.newCachedThreadPool(), jobId,
nodeIP, getSessionID());
tunnel.open(localPort, remotePort); tunnel.open(localPort, remotePort);
return new TunnelToNode() { return new TunnelToNode() {
@Override @Override
public void close() throws IOException { public void close() throws IOException {
tunnel.close(); tunnel.close();
...@@ -243,22 +258,25 @@ public class HaaSClient { ...@@ -243,22 +258,25 @@ public class HaaSClient {
return tunnel.getLocalHost(); return tunnel.getLocalHost();
} }
}; };
} catch (IOException e) { }
catch (final IOException e) {
log.error(e.getMessage(), e); log.error(e.getMessage(), e);
throw new HaaSClientException(e); throw new HaaSClientException(e);
} }
} }
public void submitJob(long jobId) { public void submitJob(final long jobId) {
doSubmitJob(jobId); doSubmitJob(jobId);
} }
public JobInfo obtainJobInfo(long jobId) { public JobInfo obtainJobInfo(final long jobId) {
final SubmittedJobInfoExt info = getJobManagement().getCurrentInfoForJob(jobId, getSessionID()); final SubmittedJobInfoExt info = getJobManagement().getCurrentInfoForJob(
jobId, getSessionID());
final Collection<Long> tasksId = info.getTasks().getSubmittedTaskInfoExt().stream().map(ti -> ti.getId()) final Collection<Long> tasksId = info.getTasks().getSubmittedTaskInfoExt()
.collect(Collectors.toList()); .stream().map(ti -> ti.getId()).collect(Collectors.toList());
return new JobInfo() { return new JobInfo() {
private List<String> ips; private List<String> ips;
@Override @Override
...@@ -298,26 +316,32 @@ public class HaaSClient { ...@@ -298,26 +316,32 @@ public class HaaSClient {
}; };
} }
public Collection<JobFileContentExt> downloadPartsOfJobFiles(Long jobId, HaaSClient.SynchronizableFiles files) { public Collection<JobFileContentExt> downloadPartsOfJobFiles(final Long jobId,
ArrayOfTaskFileOffsetExt fileOffsetExt = new ArrayOfTaskFileOffsetExt(); final HaaSClient.SynchronizableFiles files)
{
final ArrayOfTaskFileOffsetExt fileOffsetExt =
new ArrayOfTaskFileOffsetExt();
fileOffsetExt.getTaskFileOffsetExt().addAll(files.getFiles()); fileOffsetExt.getTaskFileOffsetExt().addAll(files.getFiles());
return getFileTransfer().downloadPartsOfJobFilesFromCluster(jobId, fileOffsetExt, getSessionID()) return getFileTransfer().downloadPartsOfJobFilesFromCluster(jobId,
.getJobFileContentExt(); fileOffsetExt, getSessionID()).getJobFileContentExt();
} }
public Collection<String> getChangedFiles(long jobId) { public Collection<String> getChangedFiles(final long jobId) {
return getFileTransfer().listChangedFilesForJob(jobId, getSessionID()).getString(); return getFileTransfer().listChangedFilesForJob(jobId, getSessionID())
.getString();
} }
public void cancelJob(Long jobId) { public void cancelJob(final Long jobId) {
getJobManagement().cancelJob(jobId, getSessionID()); getJobManagement().cancelJob(jobId, getSessionID());
} }
public void deleteJob(long id) { public void deleteJob(final long id) {
getJobManagement().deleteJob(id, getSessionID()); getJobManagement().deleteJob(id, getSessionID());
} }
public HaaSDataTransfer startDataTransfer(long jobId, int nodeNumber, int port) { public HaaSDataTransfer startDataTransfer(final long jobId,
final int nodeNumber, final int port)
{
return createDataTransfer(jobId, nodeNumber, port); return createDataTransfer(jobId, nodeNumber, port);
} }
...@@ -328,81 +352,127 @@ public class HaaSClient { ...@@ -328,81 +352,127 @@ public class HaaSClient {
return sessionID; return sessionID;
} }
private HaaSFileTransferImp createFileTransfer(long jobId, TransferFileProgress progress) private HaaSFileTransferImp createFileTransfer(final long jobId,
throws RemoteException, UnsupportedEncodingException, ServiceException, JSchException { final TransferFileProgress progress) throws RemoteException,
P_FileTransferPool pool = filetransferPoolMap.computeIfAbsent(jobId, id -> new P_FileTransferPool(id)); UnsupportedEncodingException, ServiceException, JSchException
FileTransferMethodExt ft = pool.obtain(); {
final P_FileTransferPool pool = filetransferPoolMap.computeIfAbsent(jobId,
id -> new P_FileTransferPool(id));
final FileTransferMethodExt ft = pool.obtain();
try { try {
return new HaaSFileTransferImp(ft, getScpClient(ft), progress) { return new HaaSFileTransferImp(ft, getScpClient(ft), progress) {
@Override @Override
public void close() { public void close() {
super.close(); super.close();
try { try {
pool.release(); pool.release();
} catch (RemoteException | ServiceException e) { }
catch (RemoteException | ServiceException e) {
throw new HaaSClientException(e); throw new HaaSClientException(e);
} }
} }
}; };
} catch (UnsupportedEncodingException | JSchException e) { }
catch (UnsupportedEncodingException | JSchException e) {
pool.release(); pool.release();
throw e; throw e;
} }
} }
private HaaSDataTransfer createDataTransfer(long jobId, int nodeNumber, int port) { private HaaSDataTransfer createDataTransfer(final long jobId,
String host = getJobManagement().getAllocatedNodesIPs(jobId, getSessionID()).getString().get(nodeNumber); final int nodeNumber, final int port)
DataTransferWsSoap ws = getDataTransfer(); {
DataTransferMethodExt dataTransferMethodExt = ws.getDataTransferMethod(host, port, jobId, final String host = getJobManagement().getAllocatedNodesIPs(jobId,
getSessionID()); getSessionID()).getString().get(nodeNumber);
String sessionId = getSessionID(); final DataTransferWsSoap ws = getDataTransfer();
final DataTransferMethodExt dataTransferMethodExt = ws
.getDataTransferMethod(host, port, jobId, getSessionID());
final String sessionId = getSessionID();
return new HaaSDataTransfer() { return new HaaSDataTransfer() {
@Override @Override
public void close() throws IOException { public void close() throws IOException {
if (log.isDebugEnabled()) {
log.debug("close");
}
ws.endDataTransfer(dataTransferMethodExt, sessionId); ws.endDataTransfer(dataTransferMethodExt, sessionId);
if (log.isDebugEnabled()) {
log.debug("close - DONE");
}
} }
@Override @Override
public void write(byte[] buffer) { public void write(final byte[] buffer) {
if (log.isDebugEnabled()) {
log.debug("write: {}", new String(buffer));
}
ws.writeDataToJobNode(buffer, jobId, host, sessionId, false); ws.writeDataToJobNode(buffer, jobId, host, sessionId, false);
if (log.isDebugEnabled()) {
log.debug("write - DONE");
}
} }
@Override @Override
public byte[] read() { public byte[] read() {
return ws.readDataFromJobNode(jobId, host, sessionId); if (log.isDebugEnabled()) {
log.debug("read: ");
}
final byte[] result = ws.readDataFromJobNode(jobId, host, sessionId);
if (log.isDebugEnabled()) {
log.debug("read - DONE: {}", result != null ? new String(result)
: "EOF");
}
return result;
} }
@Override @Override
public void closeConnection() { public void closeConnection() {
if (log.isDebugEnabled()) {
log.debug("closeConnection");
}
ws.writeDataToJobNode(null, jobId, host, sessionId, true); ws.writeDataToJobNode(null, jobId, host, sessionId, true);
}}; if (log.isDebugEnabled()) {
log.debug("closeConnection - DONE");
}
}
};
} }
private void doSubmitJob(long jobId) { private void doSubmitJob(final long jobId) {
getJobManagement().submitJob(jobId, getSessionID()); getJobManagement().submitJob(jobId, getSessionID());
} }
private long doCreateJob(JobSettings jobSettings, Collection<Entry<String, String>> templateParameters) { private long doCreateJob(final JobSettings jobSettings,
Collection<TaskSpecificationExt> taskSpec = Arrays final Collection<Entry<String, String>> templateParameters)
.asList(createTaskSpecification(jobSettings, templateParameters)); {
JobSpecificationExt jobSpecification = createJobSpecification(jobSettings, taskSpec); final Collection<TaskSpecificationExt> taskSpec = Arrays.asList(
SubmittedJobInfoExt job = getJobManagement().createJob(jobSpecification, getSessionID()); createTaskSpecification(jobSettings, templateParameters));
final JobSpecificationExt jobSpecification = createJobSpecification(
jobSettings, taskSpec);
final SubmittedJobInfoExt job = getJobManagement().createJob(
jobSpecification, getSessionID());
return job.getId(); return job.getId();
} }
private ScpClient getScpClient(FileTransferMethodExt fileTransfer) private ScpClient getScpClient(final FileTransferMethodExt fileTransfer)
throws UnsupportedEncodingException, JSchException { throws UnsupportedEncodingException, JSchException
byte[] pvtKey = fileTransfer.getCredentials().getPrivateKey().getBytes("UTF-8"); {
return new ScpClient(fileTransfer.getServerHostname(), fileTransfer.getCredentials().getUsername(), pvtKey); final byte[] pvtKey = fileTransfer.getCredentials().getPrivateKey()
.getBytes("UTF-8");
return new ScpClient(fileTransfer.getServerHostname(), fileTransfer
.getCredentials().getUsername(), pvtKey);
} }
private JobSpecificationExt createJobSpecification(JobSettings jobSettings, private JobSpecificationExt createJobSpecification(
Collection<TaskSpecificationExt> tasks) { final JobSettings jobSettings, final Collection<TaskSpecificationExt> tasks)
JobSpecificationExt testJob = new JobSpecificationExt(); {
final JobSpecificationExt testJob = new JobSpecificationExt();
testJob.setName(jobSettings.getJobName()); testJob.setName(jobSettings.getJobName());
testJob.setMinCores(jobSettings.getNumberOfCoresPerNode() * jobSettings.getNumberOfNodes()); testJob.setMinCores(jobSettings.getNumberOfCoresPerNode() * jobSettings
testJob.setMaxCores(jobSettings.getNumberOfCoresPerNode() * jobSettings.getNumberOfNodes()); .getNumberOfNodes());
testJob.setMaxCores(jobSettings.getNumberOfCoresPerNode() * jobSettings
.getNumberOfNodes());
testJob.setPriority(JobPriorityExt.AVERAGE); testJob.setPriority(JobPriorityExt.AVERAGE);
testJob.setProject(projectId); testJob.setProject(projectId);
testJob.setWaitingLimit(null); testJob.setWaitingLimit(null);
...@@ -414,17 +484,22 @@ public class HaaSClient { ...@@ -414,17 +484,22 @@ public class HaaSClient {
testJob.setNotifyOnStart(false); testJob.setNotifyOnStart(false);
testJob.setClusterNodeTypeId(jobSettings.getClusterNodeType()); testJob.setClusterNodeTypeId(jobSettings.getClusterNodeType());
testJob.setEnvironmentVariables(new ArrayOfEnvironmentVariableExt()); testJob.setEnvironmentVariables(new ArrayOfEnvironmentVariableExt());
testJob.setTasks(getAndFill(new ArrayOfTaskSpecificationExt(), a -> a.getTaskSpecificationExt().addAll(tasks))); testJob.setTasks(getAndFill(new ArrayOfTaskSpecificationExt(), a -> a
.getTaskSpecificationExt().addAll(tasks)));
return testJob; return testJob;
} }
private TaskSpecificationExt createTaskSpecification(JobSettings jobSettings, private TaskSpecificationExt createTaskSpecification(
Collection<Entry<String, String>> templateParameters) { final JobSettings jobSettings,
final Collection<Entry<String, String>> templateParameters)
{
TaskSpecificationExt testTask = new TaskSpecificationExt(); final TaskSpecificationExt testTask = new TaskSpecificationExt();
testTask.setName(jobSettings.getJobName() + "-task"); testTask.setName(jobSettings.getJobName() + "-task");
testTask.setMinCores(jobSettings.getNumberOfCoresPerNode() * jobSettings.getNumberOfNodes()); testTask.setMinCores(jobSettings.getNumberOfCoresPerNode() * jobSettings
testTask.setMaxCores(jobSettings.getNumberOfCoresPerNode() * jobSettings.getNumberOfNodes()); .getNumberOfNodes());
testTask.setMaxCores(jobSettings.getNumberOfCoresPerNode() * jobSettings
.getNumberOfNodes());
testTask.setWalltimeLimit(jobSettings.getWalltimeLimit()); testTask.setWalltimeLimit(jobSettings.getWalltimeLimit());
testTask.setRequiredNodes(null); testTask.setRequiredNodes(null);
testTask.setIsExclusive(false); testTask.setIsExclusive(false);
...@@ -438,29 +513,33 @@ public class HaaSClient { ...@@ -438,29 +513,33 @@ public class HaaSClient {
testTask.setCommandTemplateId(jobSettings.getTemplateId()); testTask.setCommandTemplateId(jobSettings.getTemplateId());
testTask.setEnvironmentVariables(new ArrayOfEnvironmentVariableExt()); testTask.setEnvironmentVariables(new ArrayOfEnvironmentVariableExt());
testTask.setDependsOn(null); testTask.setDependsOn(null);
testTask.setTemplateParameterValues(getAndFill(new ArrayOfCommandTemplateParameterValueExt(), testTask.setTemplateParameterValues(getAndFill(
t -> t.getCommandTemplateParameterValueExt() new ArrayOfCommandTemplateParameterValueExt(), t -> t
.addAll(templateParameters.stream() .getCommandTemplateParameterValueExt().addAll(templateParameters
.map(pair -> createCommandTemplateParameterValueExt(pair.getKey(), pair.getValue())) .stream().map(pair -> createCommandTemplateParameterValueExt(pair
.collect(Collectors.toList())))); .getKey(), pair.getValue())).collect(Collectors.toList()))));
return testTask; return testTask;
} }
private String authenticate() { private String authenticate() {
return getUserAndLimitationManagement() return getUserAndLimitationManagement().authenticateUserPassword(
.authenticateUserPassword(createPasswordCredentialsExt(settings.getUserName(), settings.getPassword())); createPasswordCredentialsExt(settings.getUserName(), settings
.getPassword()));
} }
synchronized private DataTransferWsSoap getDataTransfer() { synchronized private DataTransferWsSoap getDataTransfer() {
if(dataTransferWs == null) { if (dataTransferWs == null) {
dataTransferWs = new DataTransferWs().getDataTransferWsSoap12(); dataTransferWs = new DataTransferWs().getDataTransferWsSoap12();
} }
return dataTransferWs; return dataTransferWs;
} }
synchronized private UserAndLimitationManagementWsSoap getUserAndLimitationManagement() { synchronized private UserAndLimitationManagementWsSoap
getUserAndLimitationManagement()
{
if (userAndLimitationManagement == null) { if (userAndLimitationManagement == null) {
userAndLimitationManagement = new UserAndLimitationManagementWs().getUserAndLimitationManagementWsSoap12(); userAndLimitationManagement = new UserAndLimitationManagementWs()
.getUserAndLimitationManagementWsSoap12();
} }
return userAndLimitationManagement; return userAndLimitationManagement;
} }
...@@ -479,51 +558,54 @@ public class HaaSClient { ...@@ -479,51 +558,54 @@ public class HaaSClient {
return fileTransferWS; return fileTransferWS;
} }
public static class P_ProgressNotifierDecorator4Size extends P_ProgressNotifierDecorator { public static class P_ProgressNotifierDecorator4Size extends
P_ProgressNotifierDecorator
{
private static final int SIZE_RATIO = 20; private static final int SIZE_RATIO = 20;
public P_ProgressNotifierDecorator4Size(ProgressNotifier notifier) { public P_ProgressNotifierDecorator4Size(final ProgressNotifier notifier) {
super(notifier); super(notifier);
} }
@Override @Override
public void setItemCount(int count, int total) { public void setItemCount(final int count, final int total) {
super.setItemCount(count, total); super.setItemCount(count, total);
setCount(count, total * SIZE_RATIO); setCount(count, total * SIZE_RATIO);
} }
} }
public static class P_ProgressNotifierDecorator implements ProgressNotifier { public static class P_ProgressNotifierDecorator implements ProgressNotifier {
private final ProgressNotifier notifier; private final ProgressNotifier notifier;
public P_ProgressNotifierDecorator(ProgressNotifier notifier) { public P_ProgressNotifierDecorator(final ProgressNotifier notifier) {
this.notifier = notifier; this.notifier = notifier;
} }
@Override @Override
public void setTitle(String title) { public void setTitle(final String title) {
notifier.setTitle(title); notifier.setTitle(title);
} }
@Override @Override
public void setCount(int count, int total) { public void setCount(final int count, final int total) {
notifier.setCount(count, total); notifier.setCount(count, total);
} }
@Override @Override
public void addItem(Object item) { public void addItem(final Object item) {
notifier.addItem(item); notifier.addItem(item);
} }
@Override @Override
public void setItemCount(int count, int total) { public void setItemCount(final int count, final int total) {
notifier.setItemCount(count, total); notifier.setItemCount(count, total);
} }
@Override @Override
public void itemDone(Object item) { public void itemDone(final Object item) {
notifier.itemDone(item); notifier.itemDone(item);
} }
...@@ -544,17 +626,22 @@ public class HaaSClient { ...@@ -544,17 +626,22 @@ public class HaaSClient {
} }
private class P_FileTransferPool { private class P_FileTransferPool {
private FileTransferMethodExt holded; private FileTransferMethodExt holded;
private int counter; private int counter;
private final P_Supplier<FileTransferMethodExt> factory; private final P_Supplier<FileTransferMethodExt> factory;
private final P_Consumer<FileTransferMethodExt> destroyer; private final P_Consumer<FileTransferMethodExt> destroyer;
public P_FileTransferPool(long jobId) { public P_FileTransferPool(final long jobId) {
this.factory = () -> getFileTransfer().getFileTransferMethod(jobId, getSessionID()); this.factory = () -> getFileTransfer().getFileTransferMethod(jobId,
this.destroyer = val -> getFileTransfer().endFileTransfer(jobId, val, sessionID); getSessionID());
this.destroyer = val -> getFileTransfer().endFileTransfer(jobId, val,
sessionID);
} }
public synchronized FileTransferMethodExt obtain() throws RemoteException, ServiceException { public synchronized FileTransferMethodExt obtain() throws RemoteException,
ServiceException
{
if (holded == null) { if (holded == null) {
holded = factory.get(); holded = factory.get();
} }
...@@ -562,7 +649,9 @@ public class HaaSClient { ...@@ -562,7 +649,9 @@ public class HaaSClient {
return holded; return holded;
} }
public synchronized void release() throws RemoteException, ServiceException { public synchronized void release() throws RemoteException,
ServiceException
{
if (--counter == 0) { if (--counter == 0) {
destroyer.accept(holded); destroyer.accept(holded);
holded = null; holded = null;
...@@ -571,24 +660,30 @@ public class HaaSClient { ...@@ -571,24 +660,30 @@ public class HaaSClient {
} }
private static <T> T getAndFill(T value, Consumer<T> filler) { private static <T> T getAndFill(final T value, final Consumer<T> filler) {
filler.accept(value); filler.accept(value);
return value; return value;
} }
private static Calendar toGregorian(XMLGregorianCalendar time) { private static Calendar toGregorian(final XMLGregorianCalendar time) {
return Optional.ofNullable(time).map(t -> t.toGregorianCalendar()).orElse(null); return Optional.ofNullable(time).map(t -> t.toGregorianCalendar()).orElse(
null);
} }
private static CommandTemplateParameterValueExt createCommandTemplateParameterValueExt(String key, String value) { private static CommandTemplateParameterValueExt
CommandTemplateParameterValueExt result = new CommandTemplateParameterValueExt(); createCommandTemplateParameterValueExt(final String key, final String value)
{
final CommandTemplateParameterValueExt result =
new CommandTemplateParameterValueExt();
result.setCommandParameterIdentifier(key); result.setCommandParameterIdentifier(key);
result.setParameterValue(value); result.setParameterValue(value);
return result; return result;
} }
private static PasswordCredentialsExt createPasswordCredentialsExt(String userName, String password) { private static PasswordCredentialsExt createPasswordCredentialsExt(
PasswordCredentialsExt result = new PasswordCredentialsExt(); final String userName, final String password)
{
final PasswordCredentialsExt result = new PasswordCredentialsExt();
result.setUsername(userName); result.setUsername(userName);
result.setPassword(password); result.setPassword(password);
return result; return result;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment