Skip to content
Snippets Groups Projects
Commit 0d96f8c0 authored by juanf's avatar juanf
Browse files

SSDM-9408 : More logging for the ELN migrations

parent 9242e8c9
No related branches found
No related tags found
No related merge requests found
......@@ -7,7 +7,10 @@ import ch.ethz.sis.openbis.generic.asapi.v3.dto.sample.id.SamplePermId;
import ch.ethz.sis.openbis.generic.asapi.v3.dto.sample.search.SampleSearchCriteria;
import ch.ethz.sis.openbis.generic.asapi.v3.dto.sample.update.SampleUpdate;
import ch.ethz.sis.openbis.generic.server.asapi.v3.IApplicationServerInternalApi;
import ch.systemsx.cisd.common.logging.LogCategory;
import ch.systemsx.cisd.common.logging.LogFactory;
import ch.systemsx.cisd.openbis.generic.server.CommonServiceProvider;
import org.apache.log4j.Logger;
import org.w3c.dom.*;
import javax.xml.parsers.DocumentBuilder;
......@@ -18,6 +21,8 @@ import java.util.List;
public class ELNAnnotationsMigration {
private static final Logger operationLog = LogFactory.getLogger(LogCategory.OPERATION, ELNAnnotationsMigration.class);
private static boolean contains(String permId, List<Sample> samples) {
for (Sample sample:samples) {
if (sample.getPermId().getPermId().equals(permId)) {
......@@ -28,7 +33,7 @@ public class ELNAnnotationsMigration {
}
public static void beforeUpgrade() throws Exception {
System.out.println("ELNAnnotationsMigration beforeUpgrade START");
operationLog.info("ELNAnnotationsMigration beforeUpgrade START");
IApplicationServerInternalApi api = CommonServiceProvider.getApplicationServerApi();
String sessionToken = api.loginAsSystem();
SampleSearchCriteria criteria = new SampleSearchCriteria();
......@@ -45,13 +50,19 @@ public class ELNAnnotationsMigration {
int from = 0;
int count = 10000;
int total = results.getTotalCount();
System.out.println("ELNAnnotationsMigration from: " + from + " count: " + count + " total: " + total);
operationLog.info("ELNAnnotationsMigration from: " + from + " count: " + count + " total: " + total);
List<SampleUpdate> sampleUpdates = new ArrayList<>();
int exceptionsTotal = 0;
List<String> exceptionsPermIds = new ArrayList<>();
int skippedTotal = 0;
List<String> skippedPermIds = new ArrayList<>();
while (total > from) {
options.from(from);
options.count(count);
System.out.println("ELNAnnotationsMigration from: " + from + " count: " + count + " total: " + total);
operationLog.info("ELNAnnotationsMigration from: " + from + " count: " + count + " total: " + total);
for (Sample sample:api.searchSamples(sessionToken, criteria, options).getObjects()) {
SampleUpdate sampleUpdate = null;
String annotations = sample.getProperty("$ANNOTATIONS_STATE");
......@@ -104,9 +115,17 @@ public class ELNAnnotationsMigration {
}
}
} catch (Exception ex) {
exceptionsTotal++;
exceptionsPermIds.add(sample.getPermId().getPermId());
operationLog.info("ELNAnnotationsMigration FAILED: " + sample.getPermId().getPermId() + " $ANNOTATIONS_STATE = " + annotations);
ex.printStackTrace();
}
} else {
skippedTotal++;
skippedPermIds.add(sample.getPermId().getPermId());
operationLog.info("ELNAnnotationsMigration SKIPPED: " + sample.getPermId().getPermId() + " $ANNOTATIONS_STATE = " + annotations);
}
if (sampleUpdate != null) {
sampleUpdates.add(sampleUpdate);
}
......@@ -114,9 +133,13 @@ public class ELNAnnotationsMigration {
from = from + count;
}
System.out.println("ELNAnnotationsMigration sampleUpdates.size: " + sampleUpdates.size());
operationLog.info("=== ELNAnnotationsMigration Summary ===");
operationLog.info("ELNAnnotationsMigration exceptionsTotal: " + exceptionsTotal);
operationLog.info("ELNAnnotationsMigration skippedTotal: " + skippedTotal);
operationLog.info("ELNAnnotationsMigration updateSamples sampleUpdates.size: " + sampleUpdates.size());
api.updateSamples(sessionToken, sampleUpdates);
System.out.println("ELNAnnotationsMigration beforeUpgrade END");
operationLog.info("ELNAnnotationsMigration exceptionsPermIds: " + exceptionsPermIds);
operationLog.info("ELNAnnotationsMigration skippedPermIds: " + skippedPermIds);
operationLog.info("ELNAnnotationsMigration beforeUpgrade END");
}
}
\ No newline at end of file
......@@ -14,9 +14,12 @@ import ch.ethz.sis.openbis.generic.asapi.v3.dto.property.PropertyAssignment;
import ch.ethz.sis.openbis.generic.asapi.v3.dto.property.PropertyType;
import ch.ethz.sis.openbis.generic.asapi.v3.dto.property.create.PropertyAssignmentCreation;
import ch.ethz.sis.openbis.generic.server.asapi.v3.IApplicationServerInternalApi;
import ch.systemsx.cisd.common.logging.LogCategory;
import ch.systemsx.cisd.common.logging.LogFactory;
import ch.systemsx.cisd.openbis.generic.server.CommonServiceProvider;
import ch.systemsx.cisd.openbis.generic.server.ComponentNames;
import ch.systemsx.cisd.openbis.generic.server.dataaccess.db.DAOFactory;
import org.apache.log4j.Logger;
import org.hibernate.Session;
import org.hibernate.internal.SessionImpl;
import org.hibernate.query.NativeQuery;
......@@ -31,6 +34,8 @@ import java.util.stream.Stream;
public class ELNCollectionTypeMigration {
private static final Logger operationLog = LogFactory.getLogger(LogCategory.OPERATION, ELNCollectionTypeMigration.class);
private static final String COLLECTION = "COLLECTION";
private static final String[] experimentsOfTypeCollection = new String[]{
......@@ -178,7 +183,7 @@ public class ELNCollectionTypeMigration {
}
private static List executeQuery(String SQL, String key, Object value) {
//System.out.println("SQL: " + SQL + " Key: " + key + " Value: " + value);
//operationLog.info("SQL: " + SQL + " Key: " + key + " Value: " + value);
DAOFactory daoFactory = (DAOFactory) CommonServiceProvider.getApplicationContext().getBean(ComponentNames.DAO_FACTORY);
Session currentSession = daoFactory.getSessionFactory().getCurrentSession();
NativeQuery nativeQuery = currentSession.createNativeQuery(SQL);
......@@ -221,12 +226,12 @@ public class ELNCollectionTypeMigration {
}
public static void beforeUpgrade() {
System.out.println("ELNCollectionTypeMigration beforeUpgrade START");
operationLog.info("ELNCollectionTypeMigration beforeUpgrade START");
// Obtain property types used by experiments that should be of type COLLECTION
for (String experimentCode:experimentsOfTypeCollection) {
Set<ExperimentType> experimentTypes = getExperimentTypes(new String[]{experimentCode});
if (!experimentTypes.isEmpty()) {
//System.out.println("EXPERIMENT_CODE: " + experimentCode + " IS OF TYPE: " + experimentTypes.iterator().next().getCode());
//operationLog.info("EXPERIMENT_CODE: " + experimentCode + " IS OF TYPE: " + experimentTypes.iterator().next().getCode());
ExperimentType experimentType = experimentTypes.iterator().next();
if (!experimentType.getCode().equals(COLLECTION)) {
// Property Type used
......@@ -266,21 +271,21 @@ public class ELNCollectionTypeMigration {
BigInteger oldAssignment = experiment_prty_id_2_etpt_id.get(propertyTechId);
BigInteger newAssignment = collection_prty_id_2_etpt_id.get(propertyTechId);
final String UPDATE_PROPERTY_ASSIGNMENT = "UPDATE experiment_properties SET etpt_id = :new_etpt_id WHERE etpt_id = :old_etpt_id";
System.out.println("ELNCollectionTypeMigration - Swap for property tech id : " + propertyTechId + " : " + oldAssignment + " <> " + newAssignment);
operationLog.info("ELNCollectionTypeMigration - Swap for property tech id : " + propertyTechId + " : " + oldAssignment + " <> " + newAssignment);
executeUpdate(UPDATE_PROPERTY_ASSIGNMENT, "old_etpt_id", oldAssignment, "new_etpt_id", newAssignment);
}
// Update type
final String UPDATE_TYPE = "UPDATE experiments_all SET exty_id = :exty_id WHERE code = :code";
executeUpdate(UPDATE_TYPE, "exty_id", collectionTypeTechId, "code", experimentCode);
System.out.println("ELNCollectionTypeMigration - Update for : " + experimentCode + " : exty_id : " + collectionTypeTechId);
operationLog.info("ELNCollectionTypeMigration - Update for : " + experimentCode + " : exty_id : " + collectionTypeTechId);
}
}
}
for (Map.Entry<String, String> entry : PROPERTY_UPDATES_MAP.entrySet()) {
System.out.println("Going to Execute PROPERTY_UPDATE: " + entry.getKey());
operationLog.info("Going to Execute PROPERTY_UPDATE: " + entry.getKey());
String query = String.format("UPDATE property_types SET code = '%s' WHERE code = '%s' and " +
"(select count(*) from property_types where code = '%s') = 0 and " +
......@@ -288,18 +293,18 @@ public class ELNCollectionTypeMigration {
entry.getValue(), entry.getKey(), entry.getValue());
executeUpdate(query, null, null, null, null);
System.out.println("PROPERTY_UPDATE DONE");
operationLog.info("PROPERTY_UPDATE DONE");
}
System.out.println("ELNCollectionTypeMigration beforeUpgrade END");
operationLog.info("ELNCollectionTypeMigration beforeUpgrade END");
}
public static void afterUpgrade() {
System.out.println("ELNCollectionTypeMigration afterUpgrade START");
operationLog.info("ELNCollectionTypeMigration afterUpgrade START");
for (String WIDGET_POST_UPDATE:WIDGET_POST_UPDATES) {
System.out.println("Going to Execute WIDGET_POST_UPDATES: " + WIDGET_POST_UPDATE);
operationLog.info("Going to Execute WIDGET_POST_UPDATES: " + WIDGET_POST_UPDATE);
executeNativeUpdate(WIDGET_POST_UPDATE);
System.out.println("WIDGET_POST_UPDATE DONE");
operationLog.info("WIDGET_POST_UPDATE DONE");
}
System.out.println("ELNCollectionTypeMigration afterUpgrade END");
operationLog.info("ELNCollectionTypeMigration afterUpgrade END");
}
}
......@@ -21,8 +21,10 @@ from ch.ethz.sis.openbis.generic.asapi.v3.dto.service import CustomASServiceExec
from ch.systemsx.cisd.openbis.generic.server.jython.api.v1.impl import MasterDataRegistrationHelper
import sys
from ch.systemsx.cisd.openbis.generic.server.hotfix import ELNAnnotationsMigration
from ch.systemsx.cisd.openbis.generic.server.hotfix import ELNCollectionTypeMigration
ELNAnnotationsMigration.beforeUpgrade()
ELNCollectionTypeMigration.beforeUpgrade()
helper = MasterDataRegistrationHelper(sys.path)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment