2009-10-18 03:38:07 +02:00
package net.yacy ;
2006-01-17 22:33:19 +01:00
// migration.java
// -----------------------
2006-05-12 16:35:56 +02:00
// (C) by Alexander Schier
2006-01-17 22:33:19 +01:00
//
2011-03-08 02:51:51 +01:00
// $LastChangedDate$
// $LastChangedRevision$
// $LastChangedBy$
2006-01-17 22:33:19 +01:00
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
2013-05-13 04:06:57 +02:00
import net.yacy.search.index.ReindexSolrBusyThread ;
2006-01-21 17:39:57 +01:00
import java.io.File ;
import java.io.IOException ;
2013-07-18 13:26:07 +02:00
import java.util.Collection ;
2013-05-17 14:13:07 +02:00
import java.util.HashSet ;
import java.util.Iterator ;
2008-10-25 02:11:03 +02:00
import java.util.List ;
2016-03-20 03:34:28 +01:00
import java.util.Locale ;
2013-05-17 14:13:07 +02:00
import java.util.Set ;
2017-12-08 15:12:08 +01:00
import java.util.StringTokenizer ;
2006-01-21 17:39:57 +01:00
2012-09-21 16:46:57 +02:00
import net.yacy.cora.order.Base64Order ;
import net.yacy.cora.order.Digest ;
2009-10-10 03:14:19 +02:00
import net.yacy.kelondro.util.FileUtils ;
2011-09-25 18:59:06 +02:00
import net.yacy.search.Switchboard ;
import net.yacy.search.SwitchboardConstants ;
2006-01-17 22:33:19 +01:00
2012-06-22 11:39:17 +02:00
import com.google.common.io.Files ;
2013-12-25 05:20:13 +01:00
import net.yacy.cora.protocol.TimeoutRequest ;
2013-05-13 04:06:57 +02:00
import net.yacy.cora.storage.Configuration.Entry ;
2013-07-09 14:28:25 +02:00
import net.yacy.cora.util.ConcurrentLog ;
2013-05-13 04:06:57 +02:00
import net.yacy.kelondro.workflow.BusyThread ;
import net.yacy.search.schema.CollectionConfiguration ;
2013-05-15 23:16:32 +02:00
import net.yacy.search.schema.CollectionSchema ;
import org.apache.solr.client.solrj.SolrServerException ;
2013-07-18 13:26:07 +02:00
import org.apache.solr.client.solrj.response.LukeResponse.FieldInfo ;
2012-06-22 11:39:17 +02:00
2006-01-17 22:33:19 +01:00
public class migration {
2016-03-20 03:34:28 +01:00
//SVN constants (version & revision format = v.vvv0rrrr)
public static final double TAGDB_WITH_TAGHASH = 0 . 43101635 ; //tagDB keys are tagHashes instead of plain tagname.
public static final double NEW_OVERLAYS = 0 . 56504422 ;
public static final double IDX_HOST_VER = 0 . 99007724 ; // api for index retrieval: host index
2016-04-17 04:42:05 +02:00
public static final double SSLPORT_CFG = 1 . 67009578 ; // https port in cfg
2017-12-08 15:12:08 +01:00
/** Removal of deprecated IPAccessHandler for white list implementation (serverClient setting) */
public static final double NEW_IPPATTERNS = 1 . 92109489 ;
2016-03-20 03:34:28 +01:00
/ * *
* Migrates older configuratin to current version
* @param sb
* @param fromVer the long version & revision ( example 1 . 83009123 )
* @param toRev to current version
* /
public static void migrate ( final Switchboard sb , final double fromVer , final double toVer ) {
if ( fromVer < toVer ) {
if ( fromVer < TAGDB_WITH_TAGHASH ) {
2006-02-14 11:00:12 +01:00
migrateBookmarkTagsDB ( sb ) ;
2006-07-17 17:49:42 +02:00
}
2016-03-20 03:34:28 +01:00
if ( fromVer < NEW_OVERLAYS ) {
2006-07-18 13:07:30 +02:00
migrateDefaultFiles ( sb ) ;
2006-02-14 11:00:12 +01:00
}
2017-12-08 15:12:08 +01:00
if ( fromVer < NEW_IPPATTERNS ) {
migrateServerClientSetting ( sb ) ;
}
2016-03-20 03:34:28 +01:00
// use String.format to cut-off small rounding errors
ConcurrentLog . info ( " MIGRATION " , " Migrating from " + String . format ( Locale . US , " %.8f " , fromVer ) + " to " + String . format ( Locale . US , " %.8f " , toVer ) ) ;
if ( fromVer < 0 . 47d ) {
presetPasswords ( sb ) ;
migrateSwitchConfigSettings ( sb ) ;
migrateWorkFiles ( sb ) ;
}
2006-09-27 01:41:54 +02:00
}
2016-04-14 22:14:32 +02:00
installSkins ( sb ) ; // FIXME: yes, bad fix for quick release 0.47
2013-12-25 05:20:13 +01:00
// ssl/https support currently on hardcoded default port 8443 (v1.67/9563)
// make sure YaCy can start (disable ssl/https support if port is used)
2013-12-25 05:33:00 +01:00
if ( sb . getConfigBool ( " server.https " , false ) ) {
2016-04-17 04:42:05 +02:00
int sslport = 8443 ;
if ( fromVer > SSLPORT_CFG ) {
2017-03-18 20:02:26 +01:00
sslport = sb . getConfigInt ( SwitchboardConstants . SERVER_SSLPORT , 8443 ) ;
2016-04-17 04:42:05 +02:00
}
if ( TimeoutRequest . ping ( " 127.0.0.1 " , sslport , 3000 ) ) {
2014-09-16 23:14:13 +02:00
sb . setConfig ( " server.https " , false ) ;
2016-04-17 04:42:05 +02:00
ConcurrentLog . config ( " MIGRATION " , " disabled https support (reason: port already used) " ) ;
2014-09-16 23:14:13 +02:00
}
2013-12-25 05:20:13 +01:00
}
2006-02-12 17:46:43 +01:00
}
2006-07-18 13:07:30 +02:00
/ *
* remove the static defaultfiles . We use them through a overlay now .
* /
2009-07-19 22:37:44 +02:00
public static void migrateDefaultFiles ( final Switchboard sb ) {
2006-07-18 13:07:30 +02:00
File file = new File ( sb . htDocsPath , " share/dir.html " ) ;
if ( file . exists ( ) )
2008-08-06 21:43:12 +02:00
delete ( file ) ;
2006-07-18 13:07:30 +02:00
file = new File ( sb . htDocsPath , " share/dir.class " ) ;
if ( file . exists ( ) )
2008-08-06 21:43:12 +02:00
delete ( file ) ;
2006-07-18 13:07:30 +02:00
file = new File ( sb . htDocsPath , " share/dir.java " ) ;
if ( file . exists ( ) )
2008-08-06 21:43:12 +02:00
delete ( file ) ;
2006-07-18 13:07:30 +02:00
file = new File ( sb . htDocsPath , " www/welcome.html " ) ;
if ( file . exists ( ) )
2008-08-06 21:43:12 +02:00
delete ( file ) ;
2006-07-18 13:07:30 +02:00
file = new File ( sb . htDocsPath , " www/welcome.java " ) ;
if ( file . exists ( ) )
2008-08-06 21:43:12 +02:00
delete ( file ) ;
2006-07-18 13:07:30 +02:00
file = new File ( sb . htDocsPath , " www/welcome.class " ) ;
if ( file . exists ( ) )
2008-08-06 21:43:12 +02:00
delete ( file ) ;
2006-07-18 13:07:30 +02:00
}
2011-06-23 17:39:52 +02:00
2009-09-24 14:54:45 +02:00
/ *
* copy skins from the release to DATA / SKINS .
* /
2009-07-19 22:37:44 +02:00
public static void installSkins ( final Switchboard sb ) {
2013-07-26 19:51:34 +02:00
final File skinsPath = sb . getDataPath ( " skinPath " , SwitchboardConstants . SKINS_PATH_DEFAULT ) ;
2010-09-02 21:24:22 +02:00
final File defaultSkinsPath = new File ( sb . getAppPath ( ) , " skins " ) ;
2009-09-24 14:54:45 +02:00
if ( defaultSkinsPath . exists ( ) ) {
2009-11-08 23:58:57 +01:00
final List < String > skinFiles = FileUtils . getDirListing ( defaultSkinsPath . getAbsolutePath ( ) ) ;
2008-08-06 21:43:12 +02:00
mkdirs ( skinsPath ) ;
2011-06-23 17:39:52 +02:00
for ( final String skinFile : skinFiles ) {
2009-09-24 14:54:45 +02:00
if ( skinFile . endsWith ( " .css " ) ) {
2011-06-23 17:39:52 +02:00
final File from = new File ( defaultSkinsPath , skinFile ) ;
final File to = new File ( skinsPath , skinFile ) ;
2009-09-24 14:54:45 +02:00
if ( from . lastModified ( ) > to . lastModified ( ) ) try {
2012-06-22 11:39:17 +02:00
Files . copy ( from , to ) ;
2009-09-24 14:54:45 +02:00
} catch ( final IOException e ) { }
2006-03-17 22:09:07 +01:00
}
}
}
2006-03-17 21:48:00 +01:00
String skin = sb . getConfig ( " currentSkin " , " default " ) ;
if ( skin . equals ( " " ) ) {
skin = " default " ;
}
2013-07-26 19:51:34 +02:00
final File skinsDir = sb . getDataPath ( " skinPath " , SwitchboardConstants . SKINS_PATH_DEFAULT ) ;
2008-08-02 14:12:04 +02:00
final File skinFile = new File ( skinsDir , skin + " .css " ) ;
2010-09-02 21:24:22 +02:00
final File htdocsPath = new File ( sb . getDataPath ( SwitchboardConstants . HTDOCS_PATH , SwitchboardConstants . HTROOT_PATH_DEFAULT ) , " env " ) ;
2008-08-02 14:12:04 +02:00
final File styleFile = new File ( htdocsPath , " style.css " ) ;
2006-03-17 21:48:00 +01:00
if ( ! skinFile . exists ( ) ) {
if ( styleFile . exists ( ) ) {
2013-07-09 14:28:25 +02:00
ConcurrentLog . info ( " MIGRATION " , " Skin " + skin + " not found. Keeping old skin. " ) ;
2006-03-17 21:48:00 +01:00
} else {
2013-07-09 14:28:25 +02:00
ConcurrentLog . severe ( " MIGRATION " , " Skin " + skin + " and no existing Skin found. " ) ;
2006-03-17 21:48:00 +01:00
}
} else {
try {
2008-08-06 21:43:12 +02:00
mkdirs ( styleFile . getParentFile ( ) ) ;
2012-06-22 11:39:17 +02:00
Files . copy ( skinFile , styleFile ) ;
2013-07-09 14:28:25 +02:00
ConcurrentLog . info ( " MIGRATION " , " copied new Skinfile " ) ;
2008-08-02 14:12:04 +02:00
} catch ( final IOException e ) {
2013-07-09 14:28:25 +02:00
ConcurrentLog . severe ( " MIGRATION " , " Cannot copy skinfile. " ) ;
2006-03-17 21:48:00 +01:00
}
}
}
2008-08-06 21:43:12 +02:00
/ * *
* @param path
* /
private static void mkdirs ( final File path ) {
if ( ! path . exists ( ) ) {
if ( ! path . mkdirs ( ) )
2013-07-09 14:28:25 +02:00
ConcurrentLog . warn ( " MIGRATION " , " could not create directories for " + path ) ;
2008-08-06 21:43:12 +02:00
}
}
2009-07-19 22:37:44 +02:00
public static void migrateBookmarkTagsDB ( final Switchboard sb ) {
2013-07-27 15:20:09 +02:00
if ( sb . bookmarksDB ! = null ) sb . bookmarksDB . close ( ) ;
2008-08-02 14:12:04 +02:00
final File tagsDBFile = new File ( sb . workPath , " bookmarkTags.db " ) ;
2006-02-14 11:00:12 +01:00
if ( tagsDBFile . exists ( ) ) {
2008-08-06 21:43:12 +02:00
delete ( tagsDBFile ) ;
2013-07-09 14:28:25 +02:00
ConcurrentLog . info ( " MIGRATION " , " Migrating bookmarkTags.db to use wordhashs as keys. " ) ;
2006-02-14 11:00:12 +01:00
}
2009-05-27 17:04:04 +02:00
try {
sb . initBookmarks ( ) ;
2011-06-23 17:39:52 +02:00
} catch ( final IOException e ) {
2013-07-09 14:28:25 +02:00
ConcurrentLog . logException ( e ) ;
2009-05-27 17:04:04 +02:00
}
2006-02-14 11:00:12 +01:00
}
2008-08-06 21:43:12 +02:00
/ * *
* @param filename
* /
private static void delete ( final File filename ) {
if ( ! filename . delete ( ) )
2013-07-09 14:28:25 +02:00
ConcurrentLog . warn ( " MIGRATION " , " could not delete " + filename ) ;
2008-08-06 21:43:12 +02:00
}
2009-07-19 22:37:44 +02:00
public static void migrateWorkFiles ( final Switchboard sb ) {
2010-09-02 21:24:22 +02:00
File file = new File ( sb . getDataPath ( ) , " DATA/SETTINGS/wiki.db " ) ;
2006-01-21 17:39:57 +01:00
File file2 ;
if ( file . exists ( ) ) {
2013-07-09 14:28:25 +02:00
ConcurrentLog . info ( " MIGRATION " , " Migrating wiki.db to " + sb . workPath ) ;
2006-01-22 18:21:46 +01:00
sb . wikiDB . close ( ) ;
2006-01-21 17:39:57 +01:00
file2 = new File ( sb . workPath , " wiki.db " ) ;
2006-01-22 18:21:46 +01:00
try {
2012-06-22 11:39:17 +02:00
Files . copy ( file , file2 ) ;
2006-01-22 18:21:46 +01:00
file . delete ( ) ;
2008-08-02 14:12:04 +02:00
} catch ( final IOException e ) {
2006-01-22 18:21:46 +01:00
}
2011-06-23 17:39:52 +02:00
2010-09-02 21:24:22 +02:00
file = new File ( sb . getDataPath ( ) , " DATA/SETTINGS/wiki-bkp.db " ) ;
2006-01-22 18:21:46 +01:00
if ( file . exists ( ) ) {
2013-07-09 14:28:25 +02:00
ConcurrentLog . info ( " MIGRATION " , " Migrating wiki-bkp.db to " + sb . workPath ) ;
2006-01-22 18:21:46 +01:00
file2 = new File ( sb . workPath , " wiki-bkp.db " ) ;
2006-01-21 17:39:57 +01:00
try {
2012-06-22 11:39:17 +02:00
Files . copy ( file , file2 ) ;
2006-01-21 17:39:57 +01:00
file . delete ( ) ;
2011-06-23 17:39:52 +02:00
} catch ( final IOException e ) { }
2006-01-21 17:39:57 +01:00
}
2009-05-27 17:04:04 +02:00
try {
sb . initWiki ( ) ;
2011-06-23 17:39:52 +02:00
} catch ( final IOException e ) {
2013-07-09 14:28:25 +02:00
ConcurrentLog . logException ( e ) ;
2009-05-27 17:04:04 +02:00
}
2006-01-21 17:39:57 +01:00
}
2011-06-23 17:39:52 +02:00
2010-09-02 21:24:22 +02:00
file = new File ( sb . getDataPath ( ) , " DATA/SETTINGS/message.db " ) ;
2006-01-22 18:21:46 +01:00
if ( file . exists ( ) ) {
2013-07-09 14:28:25 +02:00
ConcurrentLog . info ( " MIGRATION " , " Migrating message.db to " + sb . workPath ) ;
2006-01-22 18:21:46 +01:00
sb . messageDB . close ( ) ;
file2 = new File ( sb . workPath , " message.db " ) ;
try {
2012-06-22 11:39:17 +02:00
Files . copy ( file , file2 ) ;
2006-01-22 18:21:46 +01:00
file . delete ( ) ;
2008-08-02 14:12:04 +02:00
} catch ( final IOException e ) { }
2009-05-27 17:04:04 +02:00
try {
sb . initMessages ( ) ;
2011-06-23 17:39:52 +02:00
} catch ( final IOException e ) {
2013-07-09 14:28:25 +02:00
ConcurrentLog . logException ( e ) ;
2009-05-27 17:04:04 +02:00
}
2006-01-21 17:39:57 +01:00
}
2006-01-17 22:33:19 +01:00
}
2009-07-19 22:37:44 +02:00
public static void presetPasswords ( final Switchboard sb ) {
2006-01-17 22:33:19 +01:00
// set preset accounts/passwords
String acc ;
2014-01-05 04:23:44 +01:00
if ( ( acc = sb . getConfig ( SwitchboardConstants . ADMIN_ACCOUNT , " " ) ) . length ( ) > 0 ) {
2011-05-05 02:25:14 +02:00
sb . setConfig ( SwitchboardConstants . ADMIN_ACCOUNT_B64MD5 , Digest . encodeMD5Hex ( Base64Order . standardCoder . encodeString ( acc ) ) ) ;
2006-01-17 22:33:19 +01:00
}
2011-06-23 17:39:52 +02:00
2006-01-17 22:33:19 +01:00
// fix unsafe old passwords
if ( ( acc = sb . getConfig ( " proxyAccountBase64 " , " " ) ) . length ( ) > 0 ) {
2009-01-30 16:33:00 +01:00
sb . setConfig ( " proxyAccountBase64MD5 " , Digest . encodeMD5Hex ( acc ) ) ;
2006-01-17 22:33:19 +01:00
sb . setConfig ( " proxyAccountBase64 " , " " ) ;
}
if ( ( acc = sb . getConfig ( " uploadAccountBase64 " , " " ) ) . length ( ) > 0 ) {
2009-01-30 16:33:00 +01:00
sb . setConfig ( " uploadAccountBase64MD5 " , Digest . encodeMD5Hex ( acc ) ) ;
2006-01-17 22:33:19 +01:00
sb . setConfig ( " uploadAccountBase64 " , " " ) ;
}
if ( ( acc = sb . getConfig ( " downloadAccountBase64 " , " " ) ) . length ( ) > 0 ) {
2009-01-30 16:33:00 +01:00
sb . setConfig ( " downloadAccountBase64MD5 " , Digest . encodeMD5Hex ( acc ) ) ;
2006-01-17 22:33:19 +01:00
sb . setConfig ( " downloadAccountBase64 " , " " ) ;
}
}
2009-07-19 22:37:44 +02:00
public static void migrateSwitchConfigSettings ( final Switchboard sb ) {
2011-06-23 17:39:52 +02:00
2006-07-26 16:26:45 +02:00
// migration for additional parser settings
2006-01-17 22:33:19 +01:00
String value = " " ;
2006-02-04 11:50:22 +01:00
//Locales in DATA, because DATA must be writable, htroot not.
2007-07-04 12:32:30 +02:00
if ( sb . getConfig ( " locale.translated_html " , " DATA/LOCALE/htroot " ) . equals ( " htroot/locale " ) ) {
sb . setConfig ( " locale.translated_html " , " DATA/LOCALE/htroot " ) ;
2006-02-04 11:50:22 +01:00
}
2011-06-23 17:39:52 +02:00
2006-08-12 04:42:10 +02:00
// migration for blacklists
2006-08-12 16:28:14 +02:00
if ( ( value = sb . getConfig ( " proxyBlackListsActive " , " " ) ) . length ( ) > 0 ) {
2006-08-12 04:42:10 +02:00
sb . setConfig ( " proxy.BlackLists " , value ) ;
sb . setConfig ( " crawler.BlackLists " , value ) ;
sb . setConfig ( " dht.BlackLists " , value ) ;
sb . setConfig ( " search.BlackLists " , value ) ;
2007-06-04 17:36:10 +02:00
sb . setConfig ( " surftips.BlackLists " , value ) ;
2011-06-23 17:39:52 +02:00
2006-08-12 04:42:10 +02:00
sb . setConfig ( " BlackLists.Shared " , sb . getConfig ( " proxyBlackListsShared " , " " ) ) ;
2007-06-04 17:36:10 +02:00
sb . setConfig ( " proxyBlackListsActive " , " " ) ;
2006-08-12 04:42:10 +02:00
}
2011-06-23 17:39:52 +02:00
2006-09-04 13:56:47 +02:00
// migration of http specific crawler settings
if ( ( value = sb . getConfig ( " crawler.acceptLanguage " , " " ) ) . length ( ) > 0 ) {
sb . setConfig ( " crawler.http.acceptEncoding " , sb . getConfig ( " crawler.acceptEncoding " , " gzip,deflate " ) ) ;
sb . setConfig ( " crawler.http.acceptLanguage " , sb . getConfig ( " crawler.acceptLanguage " , " en-us,en;q=0.5 " ) ) ;
2011-06-23 17:39:52 +02:00
sb . setConfig ( " crawler.http.acceptCharset " , sb . getConfig ( " crawler.acceptCharset " , " ISO-8859-1,utf-8;q=0.7,*;q=0.7 " ) ) ;
}
2014-04-13 07:32:32 +02:00
// patch the blacklist because of a release strategy change from 0.7 and up
if ( ( value = sb . getConfig ( " update.blacklist " , " " ) ) . equals ( " ....[123] " ) ) {
value = " " ; // no default (remove prev. setting "...[123]" as it hits "1.71" release, added 2014-04-13)
sb . setConfig ( " update.blacklist " , value ) ;
}
2006-01-17 22:33:19 +01:00
}
2013-05-13 04:06:57 +02:00
2017-12-08 15:12:08 +01:00
/ * *
* Setting " serverClient " : migrate eventual address patterns using deprecated
* formats previously supported by the IPAccessHandler and IPAddressMap classes .
* /
public static void migrateServerClientSetting ( final Switchboard sb ) {
final String patternSeparator = " , " ;
final String white = sb . getConfig ( " serverClient " , " * " ) ;
if ( ! white . equals ( " * " ) ) {
final StringBuilder migrated = new StringBuilder ( ) ;
boolean hasDeprecated = migrateIPAddressPatterns ( patternSeparator , white , migrated ) ;
if ( hasDeprecated ) {
sb . setConfig ( " serverClient " , migrated . toString ( ) ) ;
ConcurrentLog . info ( " MIGRATION " , " Migrated serverClient setting from " + white + " to " + migrated ) ;
}
}
}
/ * *
* Convert eventual address patterns using deprecated formats previously
* supported by the IPAccessHandler and IPAddressMap classes . All parameters
* must be not null .
*
* @param patternSeparator
* pattern separator
* @param patterns
* patterns to convert
* @param migrated
* the result of the conversion . Equals the patterns String when it
* contained no pattern using a deprecated format .
* @return true when patterns contained at least one pattern using a deprecated
* format .
* /
protected static boolean migrateIPAddressPatterns ( final String patternSeparator , final String patterns ,
final StringBuilder migrated ) {
final StringTokenizer st = new StringTokenizer ( patterns , patternSeparator ) ;
boolean hasDeprecated = false ;
while ( st . hasMoreTokens ( ) ) {
final String pattern = st . nextToken ( ) ;
int idx ;
if ( pattern . indexOf ( '|' ) > 0 ) {
idx = pattern . indexOf ( '|' ) ;
} else {
idx = pattern . indexOf ( '/' ) ;
if ( idx > = 0 ) {
/ *
* First " / " character of the URI pattern used to separate it from the internet
* address . But it can now be used in CIDR notation
* /
final String intPart = pattern . substring ( idx + 1 ) ;
try {
int intValue = Integer . parseInt ( intPart ) ;
if ( intValue > = 0 & & intValue < = 128 ) {
idx = - 1 ;
} else {
/* No a valid CIDR notation : maybe a path with only numbers? */
hasDeprecated = true ;
}
} catch ( final NumberFormatException e ) {
hasDeprecated = true ;
}
}
}
String addr = idx > 0 ? pattern . substring ( 0 , idx ) : pattern ;
String path = idx > 0 ? pattern . substring ( idx ) : " /* " ;
if ( addr . endsWith ( " . " ) ) {
/ *
* Migrating prefix wildcard specification range format ( e . g . " 10.10. " becomes
* " 10.10.0.0-10.10.255.255 " ) .
* /
hasDeprecated = true ;
final String [ ] parts = addr . split ( " \\ . " ) ;
final StringBuilder migratedAddr = new StringBuilder ( addr . substring ( 0 , addr . length ( ) - 1 ) ) ;
for ( int i = parts . length ; i < 4 ; i + + ) {
migratedAddr . append ( " .0 " ) ;
}
migratedAddr . append ( " - " ) . append ( addr . substring ( 0 , addr . length ( ) - 1 ) ) ;
for ( int i = parts . length ; i < 4 ; i + + ) {
migratedAddr . append ( " .255 " ) ;
}
addr = migratedAddr . toString ( ) ;
}
if ( path . startsWith ( " | " ) | | path . startsWith ( " /*. " ) ) {
path = path . substring ( 1 ) ;
}
if ( migrated . length ( ) > 0 ) {
migrated . append ( patternSeparator ) ;
}
migrated . append ( addr ) ;
if ( ! " /* " . equals ( path ) ) {
migrated . append ( " | " ) . append ( path ) ;
}
}
return hasDeprecated ;
}
2013-05-13 04:06:57 +02:00
/ * *
* Reindex embedded solr index
* - all documents with inactive fields ( according to current schema )
* - all documents with obsolete fields
* A worker thread is initialized with fieldnames or a solr query which selects the documents for reindexing
* implemented via deployed BusyThread which is called repeatedly by system
* reindexes a fixed chunk of documents per cycle ( allowing to easy interrupt process after completion of a chunck )
* and monitoring in default process monitor ( PerformanceQueues_p . html )
* /
public static int reindexToschema ( final Switchboard sb ) {
2015-01-29 00:33:07 +01:00
BusyThread bt = sb . getThread ( ReindexSolrBusyThread . THREAD_NAME ) ;
2013-05-13 04:06:57 +02:00
// a reindex job is already running
if ( bt ! = null ) {
return bt . getJobCount ( ) ;
2013-05-15 23:16:32 +02:00
}
boolean lukeCheckok = false ;
2013-08-08 00:55:21 +02:00
Set < String > omitFields = new HashSet < String > ( 4 ) ;
2013-05-15 23:16:32 +02:00
omitFields . add ( CollectionSchema . author_sxt . getSolrFieldName ( ) ) ; // special fields to exclude from disabled check
omitFields . add ( CollectionSchema . coordinate_p_0_coordinate . getSolrFieldName ( ) ) ;
omitFields . add ( CollectionSchema . coordinate_p_1_coordinate . getSolrFieldName ( ) ) ;
2013-08-08 00:55:21 +02:00
omitFields . add ( " _version_ " ) ; // exclude internal Solr std. field from obsolete check
2013-05-13 04:06:57 +02:00
CollectionConfiguration colcfg = Switchboard . getSwitchboard ( ) . index . fulltext ( ) . getDefaultConfiguration ( ) ;
2013-05-15 23:16:32 +02:00
ReindexSolrBusyThread reidx = new ReindexSolrBusyThread ( null ) ; // ("*:*" would reindex all);
try { // get all fields contained in index
2013-07-18 13:26:07 +02:00
Collection < FieldInfo > solrfields = Switchboard . getSwitchboard ( ) . index . fulltext ( ) . getDefaultEmbeddedConnector ( ) . getFields ( ) ;
for ( FieldInfo solrfield : solrfields ) {
2015-01-29 01:22:28 +01:00
if ( ! colcfg . contains ( solrfield . getName ( ) ) & & ! omitFields . contains ( solrfield . getName ( ) ) & & ! solrfield . getName ( ) . startsWith ( CollectionSchema . VOCABULARY_PREFIX ) ) { // add found fields not in config for reindexing but omit the vocabulary fields
2013-05-15 23:16:32 +02:00
reidx . addSelectFieldname ( solrfield . getName ( ) ) ;
}
2013-05-13 04:06:57 +02:00
}
2013-05-15 23:16:32 +02:00
lukeCheckok = true ;
2013-07-17 18:31:30 +02:00
} catch ( final SolrServerException ex ) {
2013-07-09 14:28:25 +02:00
ConcurrentLog . logException ( ex ) ;
2013-05-13 04:06:57 +02:00
}
2013-05-15 23:16:32 +02:00
if ( ! lukeCheckok ) { // if luke failed alternatively use config and manual list
// add all disabled fields
Iterator < Entry > itcol = colcfg . entryIterator ( ) ;
while ( itcol . hasNext ( ) ) { // check for disabled fields in config
Entry etr = itcol . next ( ) ;
if ( ! etr . enabled ( ) & & ! omitFields . contains ( etr . key ( ) ) ) {
reidx . addSelectFieldname ( etr . key ( ) ) ;
}
}
2013-05-13 04:06:57 +02:00
2013-05-15 23:16:32 +02:00
// add obsolete fields (not longer part of main index)
reidx . addSelectFieldname ( " author_s " ) ;
reidx . addSelectFieldname ( " css_tag_txt " ) ;
reidx . addSelectFieldname ( " css_url_txt " ) ;
reidx . addSelectFieldname ( " scripts_txt " ) ;
reidx . addSelectFieldname ( " images_tag_txt " ) ;
reidx . addSelectFieldname ( " images_urlstub_txt " ) ;
reidx . addSelectFieldname ( " canonical_t " ) ;
reidx . addSelectFieldname ( " frames_txt " ) ;
reidx . addSelectFieldname ( " iframes_txt " ) ;
2013-05-13 04:06:57 +02:00
2013-05-15 23:16:32 +02:00
reidx . addSelectFieldname ( " inboundlinks_tag_txt " ) ;
reidx . addSelectFieldname ( " inboundlinks_relflags_val " ) ;
reidx . addSelectFieldname ( " inboundlinks_name_txt " ) ;
reidx . addSelectFieldname ( " inboundlinks_rel_sxt " ) ;
reidx . addSelectFieldname ( " inboundlinks_text_txt " ) ;
reidx . addSelectFieldname ( " inboundlinks_text_chars_val " ) ;
reidx . addSelectFieldname ( " inboundlinks_text_words_val " ) ;
reidx . addSelectFieldname ( " inboundlinks_alttag_txt " ) ;
reidx . addSelectFieldname ( " outboundlinks_tag_txt " ) ;
reidx . addSelectFieldname ( " outboundlinks_relflags_val " ) ;
reidx . addSelectFieldname ( " outboundlinks_name_txt " ) ;
reidx . addSelectFieldname ( " outboundlinks_rel_sxt " ) ;
reidx . addSelectFieldname ( " outboundlinks_text_txt " ) ;
reidx . addSelectFieldname ( " outboundlinks_text_chars_val " ) ;
reidx . addSelectFieldname ( " outboundlinks_text_words_val " ) ;
reidx . addSelectFieldname ( " outboundlinks_alttag_txt " ) ;
}
2015-01-29 00:33:07 +01:00
sb . deployThread ( ReindexSolrBusyThread . THREAD_NAME , " Reindex Solr " , " reindex documents with obsolete fields in embedded Solr index " , " /IndexReIndexMonitor_p.html " , reidx , 0 ) ;
2013-05-13 04:06:57 +02:00
return 0 ;
}
2006-01-17 22:33:19 +01:00
}