package org.openslx.taskmanager.tasks; import java.util.Map; import org.openslx.satserver.util.Constants; import org.openslx.taskmanager.api.SystemCommandTask; import com.google.gson.annotations.Expose; public class ScpSnapshot extends SystemCommandTask { @Expose private String editId = null; @Expose private String clientIp = null; @Expose private String lectureId = null; private final Output status = new Output(); @Override protected boolean initTask() { this.setStatusObject( this.status ); if ( this.editId == null ) this.editId = ""; if ( this.clientIp == null ) this.clientIp = ""; if ( this.lectureId == null ) this.lectureId = ""; return true; } @Override protected String[] initCommandLine() { return new String[] { "/usr/bin/sudo", "-n", "-u", "root", Constants.BASEDIR + "/scripts/scp-snapshot" }; } @Override protected void initEnvironment( Map environment ) { environment.put( "TM_EDIT_ID", this.editId ); environment.put( "TM_CLIENT_IP", this.clientIp ); environment.put( "TM_LECTURE_ID", this.lectureId); } @Override protected boolean processEnded( int exitCode ) { return exitCode == 0; } @Override protected void processStdOut( String line ) { status.addMessage( line ); } @Override protected void processStdErr( String line ) { status.addMessage( line ); } /** * Output - contains additional status data of this task */ class Output { private String messages = null; private void addMessage( String str ) { if ( messages == null ) { messages = str; } else { messages += "\n" + str; } } } }