blob: 034dab5a9d23004570081d89a333b9ab32846f98 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
|
package org.openslx.taskmanager.tasks;
import java.util.concurrent.atomic.AtomicBoolean;
import org.openslx.satserver.util.Constants;
import org.openslx.taskmanager.api.SystemCommandTask;
import com.google.gson.annotations.Expose;
public class MountVmStore extends SystemCommandTask
{
@Expose
private String address = null;
@Expose
private String type = null;
@Expose
private String username = null;
@Expose
private String password = null;
private Output status = new Output();
private static AtomicBoolean isRunning = new AtomicBoolean();
@Override
protected boolean initTask()
{
this.setStatusObject( this.status );
if ( this.address == null || this.type == null ) {
status.addMessage( "Address or type not given." );
return false;
}
if ( this.username == null )
this.username = "";
if ( this.password == null )
this.password = "";
this.timeoutSeconds = 60;
return true;
}
@Override
protected String[] initCommandLine()
{
if (!isRunning.compareAndSet( false, true )) {
status.addMessage("Another operation is already in progress.");
return null;
}
return new String[] {
"/usr/bin/sudo",
"-n",
"-u", "root",
Constants.BASEDIR + "/scripts/mount-store",
"images",
this.address,
this.username,
this.password
};
}
@Override
protected boolean processEnded( int exitCode )
{
isRunning.set( false );
if ( exitCode != 0 )
status.addMessage( "Failed with exit code " + exitCode );
status.exitCode = exitCode;
return exitCode == 0;
}
@Override
protected void processStdOut( String line )
{
status.addMessage( line );
}
@Override
protected void processStdErr( String line )
{
status.addMessage( line );
}
class Output
{
public String messages = null;
public int exitCode = -111;
private void addMessage( String str )
{
if ( messages == null ) {
messages = str;
} else {
messages += "\n" + str;
}
}
}
}
|