@ -18,21 +18,20 @@
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
import java.io.IOException ;
import java.io.IOException ;
import java.text.DateFormat ;
import java.util.Date ;
import java.util.Date ;
import java.util.Iterator ;
import java.util.Iterator ;
import java.util.LinkedHashMap ;
import java.util.Map ;
import java.util.Map ;
import java.util.TreeSet ;
import java.util.TreeSet ;
import net.yacy.cora.protocol.Client ;
import net.yacy.kelondro.blob.Tables ;
import net.yacy.kelondro.blob.Tables ;
import net.yacy.kelondro.index.RowSpaceExceededException ;
import net.yacy.kelondro.index.RowSpaceExceededException ;
import net.yacy.kelondro.logging.Log ;
import net.yacy.kelondro.logging.Log ;
import net.yacy.kelondro.util.DateFormatter ;
import de.anomic.data.WorkTables ;
import de.anomic.data.WorkTables ;
import de.anomic.http.server.RequestHeader ;
import de.anomic.http.server.RequestHeader ;
import de.anomic.search.Switchboard ;
import de.anomic.search.Switchboard ;
import de.anomic.search.SwitchboardConstants ;
import de.anomic.server.serverObjects ;
import de.anomic.server.serverObjects ;
import de.anomic.server.serverSwitch ;
import de.anomic.server.serverSwitch ;
@ -42,6 +41,76 @@ public class Table_API_p {
final Switchboard sb = ( Switchboard ) env ;
final Switchboard sb = ( Switchboard ) env ;
final serverObjects prop = new serverObjects ( ) ;
final serverObjects prop = new serverObjects ( ) ;
prop . put ( "showexec" , 0 ) ;
prop . put ( "showtable" , 0 ) ;
prop . put ( "inline" , 0 ) ;
boolean inline = false ;
if ( post ! = null & & post . get ( "inline" , "false" ) . equals ( "true" ) ) {
prop . put ( "inline" , 1 ) ;
inline = true ;
}
String typefilter = ".*" ;
if ( post ! = null & & post . containsKey ( "filter" ) ) {
typefilter = post . get ( "filter" , ".*" ) ;
}
String pk ;
if ( post ! = null & & post . containsKey ( "repeat_select" ) & & ( ( pk = post . get ( "pk" ) ) ! = null ) ) try {
String action = post . get ( "repeat_select" , "off" ) ;
if ( action . equals ( "on" ) ) {
Tables . Row row = sb . tables . select ( WorkTables . TABLE_API_NAME , pk . getBytes ( ) ) ;
if ( row ! = null ) {
row . put ( WorkTables . TABLE_API_COL_APICALL_SCHEDULE_TIME , 1 ) ;
row . put ( WorkTables . TABLE_API_COL_APICALL_SCHEDULE_UNIT , "days" ) ;
WorkTables . calculateAPIScheduler ( row , false ) ;
sb . tables . update ( WorkTables . TABLE_API_NAME , row ) ;
}
}
} catch ( IOException e ) {
Log . logException ( e ) ;
} catch ( RowSpaceExceededException e ) {
Log . logException ( e ) ;
}
if ( post ! = null & & post . containsKey ( "repeat_time" ) & & ( ( pk = post . get ( "pk" ) ) ! = null ) ) try {
String action = post . get ( "repeat_time" , "off" ) ;
Tables . Row row = sb . tables . select ( WorkTables . TABLE_API_NAME , pk . getBytes ( ) ) ;
if ( row ! = null ) {
if ( action . equals ( "off" ) ) {
row . put ( WorkTables . TABLE_API_COL_APICALL_SCHEDULE_TIME , 0 ) ;
} else {
row . put ( WorkTables . TABLE_API_COL_APICALL_SCHEDULE_TIME , Integer . parseInt ( action ) ) ;
}
WorkTables . calculateAPIScheduler ( row , false ) ;
sb . tables . update ( WorkTables . TABLE_API_NAME , row ) ;
}
} catch ( IOException e ) {
Log . logException ( e ) ;
} catch ( RowSpaceExceededException e ) {
Log . logException ( e ) ;
}
if ( post ! = null & & post . containsKey ( "repeat_unit" ) & & ( ( pk = post . get ( "pk" ) ) ! = null ) ) try {
String action = post . get ( "repeat_unit" , "seldays" ) ;
Tables . Row row = sb . tables . select ( WorkTables . TABLE_API_NAME , pk . getBytes ( ) ) ;
if ( row ! = null ) {
int time = row . get ( WorkTables . TABLE_API_COL_APICALL_SCHEDULE_TIME , 1 ) ;
row . put ( WorkTables . TABLE_API_COL_APICALL_SCHEDULE_UNIT , action . substring ( 3 ) ) ;
if ( action . equals ( "selminutes" ) & & time > 0 & & time < 10 ) row . put ( WorkTables . TABLE_API_COL_APICALL_SCHEDULE_TIME , 10 ) ;
if ( action . equals ( "selminutes" ) & & time > 50 ) row . put ( WorkTables . TABLE_API_COL_APICALL_SCHEDULE_TIME , 50 ) ;
if ( action . equals ( "selhours" ) & & time > 23 ) row . put ( WorkTables . TABLE_API_COL_APICALL_SCHEDULE_TIME , 23 ) ;
if ( action . equals ( "seldays" ) & & time > 30 ) row . put ( WorkTables . TABLE_API_COL_APICALL_SCHEDULE_TIME , 30 ) ;
WorkTables . calculateAPIScheduler ( row , false ) ;
sb . tables . update ( WorkTables . TABLE_API_NAME , row ) ;
}
} catch ( IOException e ) {
Log . logException ( e ) ;
} catch ( RowSpaceExceededException e ) {
Log . logException ( e ) ;
}
if ( post ! = null & & post . get ( "deleterows" , "" ) . length ( ) > 0 ) {
if ( post ! = null & & post . get ( "deleterows" , "" ) . length ( ) > 0 ) {
for ( Map . Entry < String , String > entry : post . entrySet ( ) ) {
for ( Map . Entry < String , String > entry : post . entrySet ( ) ) {
if ( entry . getValue ( ) . startsWith ( "mark_" ) ) {
if ( entry . getValue ( ) . startsWith ( "mark_" ) ) {
@ -54,9 +123,6 @@ public class Table_API_p {
}
}
}
}
prop . put ( "showexec" , 0 ) ;
prop . put ( "showtable" , 0 ) ;
if ( post ! = null & & post . get ( "execrows" , "" ) . length ( ) > 0 ) {
if ( post ! = null & & post . get ( "execrows" , "" ) . length ( ) > 0 ) {
// create a time-ordered list of events to execute
// create a time-ordered list of events to execute
TreeSet < String > pks = new TreeSet < String > ( ) ;
TreeSet < String > pks = new TreeSet < String > ( ) ;
@ -67,28 +133,7 @@ public class Table_API_p {
}
}
// now call the api URLs and store the result status
// now call the api URLs and store the result status
final Client client = new Client ( ) ;
Map < String , Integer > l = sb . tables . execAPICall ( pks , "localhost" , ( int ) sb . getConfigLong ( "port" , 8080 ) , sb . getConfig ( "adminAccountBase64MD5" , "" ) ) ;
client . setRealm ( sb . getConfig ( "adminAccountBase64MD5" , "" ) ) ;
client . setTimout ( 120000 ) ;
LinkedHashMap < String , Integer > l = new LinkedHashMap < String , Integer > ( ) ;
for ( String pk : pks ) {
try {
Tables . Row row = sb . tables . select ( WorkTables . TABLE_API_NAME , pk . getBytes ( ) ) ;
if ( row ! = null ) {
String url = "http://localhost:" + sb . getConfig ( "port" , "8080" ) + new String ( row . get ( WorkTables . TABLE_API_COL_URL ) ) ;
url + = "&" + WorkTables . TABLE_API_COL_APICALL_PK + "=" + pk ;
url + = "&" + WorkTables . TABLE_API_COL_APICALL_COUNT + "=" + ( row . get ( WorkTables . TABLE_API_COL_APICALL_COUNT , 1 ) + 1 ) ;
url + = "&" + WorkTables . TABLE_API_COL_APICALL_SCHEDULE_TIME + "=" + row . get ( WorkTables . TABLE_API_COL_APICALL_SCHEDULE_TIME , "" ) ;
url + = "&" + WorkTables . TABLE_API_COL_APICALL_SCHEDULE_UNIT + "=" + row . get ( WorkTables . TABLE_API_COL_APICALL_SCHEDULE_UNIT , "" ) ;
client . GETbytes ( url ) ;
l . put ( url , client . getStatusCode ( ) ) ;
}
} catch ( IOException e ) {
Log . logException ( e ) ;
} catch ( RowSpaceExceededException e ) {
Log . logException ( e ) ;
}
}
// construct result table
// construct result table
prop . put ( "showexec" , 1 ) ;
prop . put ( "showexec" , 1 ) ;
@ -110,6 +155,7 @@ public class Table_API_p {
// generate table
// generate table
prop . put ( "showtable" , 1 ) ;
prop . put ( "showtable" , 1 ) ;
prop . put ( "showtable_inline" , inline ? 1 : 0 ) ;
// insert rows
// insert rows
int count = 0 ;
int count = 0 ;
@ -118,27 +164,83 @@ public class Table_API_p {
final Iterator < Tables . Row > mapIterator = sb . tables . orderBy ( plainIterator , - 1 , WorkTables . TABLE_API_COL_DATE_RECORDING ) . iterator ( ) ;
final Iterator < Tables . Row > mapIterator = sb . tables . orderBy ( plainIterator , - 1 , WorkTables . TABLE_API_COL_DATE_RECORDING ) . iterator ( ) ;
Tables . Row row ;
Tables . Row row ;
boolean dark = true ;
boolean dark = true ;
boolean scheduledactions = false ;
while ( mapIterator . hasNext ( ) ) {
while ( mapIterator . hasNext ( ) ) {
row = mapIterator . next ( ) ;
row = mapIterator . next ( ) ;
if ( row = = null ) continue ;
if ( row = = null ) continue ;
Date dfltdate = new Date ( ) ;
String type = new String ( row . get ( WorkTables . TABLE_API_COL_TYPE ) ) ;
Date date = row . containsKey ( WorkTables . TABLE_API_COL_DATE ) ? row . get ( WorkTables . TABLE_API_COL_DATE , dfltdate ) : null ;
if ( ! type . matches ( typefilter ) ) continue ;
Date now = new Date ( ) ;
Date date = row . containsKey ( WorkTables . TABLE_API_COL_DATE ) ? row . get ( WorkTables . TABLE_API_COL_DATE , now ) : null ;
Date date_recording = row . get ( WorkTables . TABLE_API_COL_DATE_RECORDING , date ) ;
Date date_recording = row . get ( WorkTables . TABLE_API_COL_DATE_RECORDING , date ) ;
Date date_last_exec = row . get ( WorkTables . TABLE_API_COL_DATE_LAST_EXEC , date ) ;
Date date_last_exec = row . get ( WorkTables . TABLE_API_COL_DATE_LAST_EXEC , date ) ;
Date date_next_exec = row . containsKey ( WorkTables . TABLE_API_COL_DATE_NEXT_EXEC ) ? row . get ( WorkTables . TABLE_API_COL_DATE_NEXT_EXEC , dfltdate ) : null ;
Date date_next_exec = row . containsKey ( WorkTables . TABLE_API_COL_DATE_NEXT_EXEC ) ? row . get ( WorkTables . TABLE_API_COL_DATE_NEXT_EXEC , now ) : null ;
int callcount = row . get ( WorkTables . TABLE_API_COL_APICALL_COUNT , 1 ) ;
int callcount = row . get ( WorkTables . TABLE_API_COL_APICALL_COUNT , 1 ) ;
prop . put ( "showtable_list_" + count + "_dark" , ( ( dark ) ? 1 : 0 ) ) ; dark = ! dark ;
String unit = row . get ( WorkTables . TABLE_API_COL_APICALL_SCHEDULE_UNIT , "days" ) ;
int time = row . get ( WorkTables . TABLE_API_COL_APICALL_SCHEDULE_TIME , 0 ) ;
prop . put ( "showtable_list_" + count + "_inline" , inline ? 1 : 0 ) ;
prop . put ( "showtable_list_" + count + "_dark" , dark ? 1 : 0 ) ; dark = ! dark ;
prop . put ( "showtable_list_" + count + "_pk" , new String ( row . getPK ( ) ) ) ;
prop . put ( "showtable_list_" + count + "_pk" , new String ( row . getPK ( ) ) ) ;
prop . put ( "showtable_list_" + count + "_count" , count ) ;
prop . put ( "showtable_list_" + count + "_count" , count ) ;
prop . put ( "showtable_list_" + count + "_callcount" , callcount ) ;
prop . put ( "showtable_list_" + count + "_callcount" , callcount ) ;
prop . put ( "showtable_list_" + count + "_dateRecording" , date_recording = = null ? "-" : DateFormatter . formatHTML ( date_recording ) ) ;
prop . put ( "showtable_list_" + count + "_dateRecording" , date_recording = = null ? "-" : DateFormat . getDateTimeInstance ( ) . format ( date_recording ) ) ;
prop . put ( "showtable_list_" + count + "_dateLastExec" , date_last_exec = = null ? "-" : DateFormatter . formatHTML ( date_last_exec ) ) ;
prop . put ( "showtable_list_" + count + "_dateLastExec" , date_last_exec = = null ? "-" : DateFormat . getDateTimeInstance ( ) . format ( date_last_exec ) ) ;
prop . put ( "showtable_list_" + count + "_dateNextExec" , date_next_exec = = null ? "-" : DateFormatter . formatHTML ( date_next_exec ) ) ;
prop . put ( "showtable_list_" + count + "_dateNextExec" , date_next_exec = = null ? "-" : DateFormat . getDateTimeInstance ( ) . format ( date_next_exec ) ) ;
prop . put ( "showtable_list_" + count + "_type" , row . get ( WorkTables . TABLE_API_COL_TYPE ) ) ;
prop . put ( "showtable_list_" + count + "_selectedMinutes" , unit . equals ( "minutes" ) ? 1 : 0 ) ;
prop . put ( "showtable_list_" + count + "_selectedHours" , unit . equals ( "hours" ) ? 1 : 0 ) ;
prop . put ( "showtable_list_" + count + "_selectedDays" , ( unit . length ( ) = = 0 | | unit . equals ( "days" ) ) ? 1 : 0 ) ;
prop . put ( "showtable_list_" + count + "_repeatTime" , time ) ;
prop . put ( "showtable_list_" + count + "_type" , type ) ;
prop . put ( "showtable_list_" + count + "_comment" , row . get ( WorkTables . TABLE_API_COL_COMMENT ) ) ;
prop . put ( "showtable_list_" + count + "_comment" , row . get ( WorkTables . TABLE_API_COL_COMMENT ) ) ;
prop . put ( "showtable_list_" + count + "_url" , "http://" + sb . myPublicIP ( ) + ":" + sb . getConfig ( "port" , "8080" ) + new String ( row . get ( WorkTables . TABLE_API_COL_URL ) ) ) ;
prop . put ( "showtable_list_" + count + "_inline_url" , "http://" + sb . myPublicIP ( ) + ":" + sb . getConfig ( "port" , "8080" ) + new String ( row . get ( WorkTables . TABLE_API_COL_URL ) ) ) ;
if ( time = = 0 ) {
prop . put ( "showtable_list_" + count + "_scheduler" , 0 ) ;
prop . put ( "showtable_list_" + count + "_scheduler_pk" , new String ( row . getPK ( ) ) ) ;
} else {
scheduledactions = true ;
prop . put ( "showtable_list_" + count + "_scheduler" , 1 ) ;
prop . put ( "showtable_list_" + count + "_scheduler_pk" , new String ( row . getPK ( ) ) ) ;
prop . put ( "showtable_list_" + count + "_scheduler_scale_" + 0 + "_time" , "off" ) ;
prop . put ( "showtable_list_" + count + "_scheduler_selectedMinutes" , 0 ) ;
prop . put ( "showtable_list_" + count + "_scheduler_selectedHours" , 0 ) ;
prop . put ( "showtable_list_" + count + "_scheduler_selectedDays" , 0 ) ;
if ( unit . equals ( "minutes" ) ) {
for ( int i = 1 ; i < = 5 ; i + + ) {
prop . put ( "showtable_list_" + count + "_scheduler_scale_" + i + "_time" , i * 10 ) ;
prop . put ( "showtable_list_" + count + "_scheduler_scale_" + i + "_selected" , 0 ) ;
}
prop . put ( "showtable_list_" + count + "_scheduler_scale_" + ( time / 10 ) + "_selected" , 1 ) ;
prop . put ( "showtable_list_" + count + "_scheduler_scale" , 6 ) ;
prop . put ( "showtable_list_" + count + "_scheduler_selectedMinutes" , 1 ) ;
} else if ( unit . equals ( "hours" ) ) {
for ( int i = 1 ; i < = 23 ; i + + ) {
prop . put ( "showtable_list_" + count + "_scheduler_scale_" + i + "_time" , i ) ;
prop . put ( "showtable_list_" + count + "_scheduler_scale_" + i + "_selected" , 0 ) ;
}
prop . put ( "showtable_list_" + count + "_scheduler_scale_" + time + "_selected" , 1 ) ;
prop . put ( "showtable_list_" + count + "_scheduler_scale" , 24 ) ;
prop . put ( "showtable_list_" + count + "_scheduler_selectedHours" , 1 ) ;
} else {
for ( int i = 1 ; i < = 30 ; i + + ) {
prop . put ( "showtable_list_" + count + "_scheduler_scale_" + i + "_time" , i ) ;
prop . put ( "showtable_list_" + count + "_scheduler_scale_" + i + "_selected" , 0 ) ;
}
prop . put ( "showtable_list_" + count + "_scheduler_scale_" + time + "_selected" , 1 ) ;
prop . put ( "showtable_list_" + count + "_scheduler_scale" , 31 ) ;
prop . put ( "showtable_list_" + count + "_scheduler_selectedDays" , 1 ) ;
}
}
prop . put ( "showtable_list_" + count + "_scheduler_inline" , inline ? "true" : "false" ) ;
prop . put ( "showtable_list_" + count + "_scheduler_filter" , typefilter ) ;
count + + ;
count + + ;
}
}
if ( scheduledactions ) {
prop . put ( "showschedulerhint" , 1 ) ;
prop . put ( "showschedulerhint_tfminutes" , sb . getConfigLong ( SwitchboardConstants . CLEANUP_BUSYSLEEP , 300000 ) / 60000 ) ;
} else {
prop . put ( "showschedulerhint" , 0 ) ;
}
} catch ( IOException e ) {
} catch ( IOException e ) {
Log . logException ( e ) ;
Log . logException ( e ) ;
}
}