Skip to content
Snippets Groups Projects
Commit 3012dd4b authored by felmer's avatar felmer
Browse files

SSDM-5897: DataSetAndPathInfoDBConsistencyCheckTask refactored to use V3 API...

SSDM-5897: DataSetAndPathInfoDBConsistencyCheckTask refactored to use V3 API instead of EncapsulatedOpenBISService.

SVN: 39092
parent 6b345f0d
No related branches found
No related tags found
No related merge requests found
...@@ -20,22 +20,26 @@ import java.text.SimpleDateFormat; ...@@ -20,22 +20,26 @@ import java.text.SimpleDateFormat;
import java.util.Date; import java.util.Date;
import java.util.List; import java.util.List;
import java.util.Properties; import java.util.Properties;
import java.util.stream.Collectors;
import org.apache.commons.lang.time.DateUtils; import org.apache.commons.lang.time.DateUtils;
import org.apache.log4j.Logger; import org.apache.log4j.Logger;
import ch.ethz.sis.openbis.generic.asapi.v3.IApplicationServerApi;
import ch.ethz.sis.openbis.generic.asapi.v3.dto.dataset.DataSet;
import ch.ethz.sis.openbis.generic.asapi.v3.dto.dataset.fetchoptions.DataSetFetchOptions;
import ch.ethz.sis.openbis.generic.asapi.v3.dto.dataset.search.DataSetSearchCriteria;
import ch.systemsx.cisd.common.logging.LogCategory; import ch.systemsx.cisd.common.logging.LogCategory;
import ch.systemsx.cisd.common.logging.LogFactory; import ch.systemsx.cisd.common.logging.LogFactory;
import ch.systemsx.cisd.common.maintenance.IMaintenanceTask; import ch.systemsx.cisd.common.maintenance.IMaintenanceTask;
import ch.systemsx.cisd.common.time.DateTimeUtils; import ch.systemsx.cisd.common.time.DateTimeUtils;
import ch.systemsx.cisd.common.utilities.ITimeProvider; import ch.systemsx.cisd.common.utilities.ITimeProvider;
import ch.systemsx.cisd.common.utilities.SystemTimeProvider; import ch.systemsx.cisd.common.utilities.SystemTimeProvider;
import ch.systemsx.cisd.openbis.dss.generic.shared.IEncapsulatedOpenBISService; import ch.systemsx.cisd.openbis.dss.generic.server.openbisauth.OpenBISAuthenticationInterceptor;
import ch.systemsx.cisd.openbis.dss.generic.shared.IHierarchicalContentProvider; import ch.systemsx.cisd.openbis.dss.generic.shared.IHierarchicalContentProvider;
import ch.systemsx.cisd.openbis.dss.generic.shared.ServiceProvider; import ch.systemsx.cisd.openbis.dss.generic.shared.ServiceProvider;
import ch.systemsx.cisd.openbis.dss.generic.shared.utils.DataSetAndPathInfoDBConsistencyChecker; import ch.systemsx.cisd.openbis.dss.generic.shared.utils.DataSetAndPathInfoDBConsistencyChecker;
import ch.systemsx.cisd.openbis.generic.shared.basic.BasicConstant; import ch.systemsx.cisd.openbis.generic.shared.basic.BasicConstant;
import ch.systemsx.cisd.openbis.generic.shared.dto.SimpleDataSetInformationDTO;
/** /**
* @author Franz-Josef Elmer * @author Franz-Josef Elmer
...@@ -53,7 +57,7 @@ public class DataSetAndPathInfoDBConsistencyCheckTask implements IMaintenanceTas ...@@ -53,7 +57,7 @@ public class DataSetAndPathInfoDBConsistencyCheckTask implements IMaintenanceTas
private static final Logger notificationLog = LogFactory.getLogger(LogCategory.NOTIFY, private static final Logger notificationLog = LogFactory.getLogger(LogCategory.NOTIFY,
DataSetAndPathInfoDBConsistencyCheckTask.class); DataSetAndPathInfoDBConsistencyCheckTask.class);
private IEncapsulatedOpenBISService service; private IApplicationServerApi service;
private IHierarchicalContentProvider fileProvider; private IHierarchicalContentProvider fileProvider;
...@@ -68,7 +72,7 @@ public class DataSetAndPathInfoDBConsistencyCheckTask implements IMaintenanceTas ...@@ -68,7 +72,7 @@ public class DataSetAndPathInfoDBConsistencyCheckTask implements IMaintenanceTas
} }
DataSetAndPathInfoDBConsistencyCheckTask(IHierarchicalContentProvider fileProvider, DataSetAndPathInfoDBConsistencyCheckTask(IHierarchicalContentProvider fileProvider,
IHierarchicalContentProvider pathInfoProvider, IEncapsulatedOpenBISService service, IHierarchicalContentProvider pathInfoProvider, IApplicationServerApi service,
ITimeProvider timeProvider) ITimeProvider timeProvider)
{ {
this.fileProvider = fileProvider; this.fileProvider = fileProvider;
...@@ -89,13 +93,20 @@ public class DataSetAndPathInfoDBConsistencyCheckTask implements IMaintenanceTas ...@@ -89,13 +93,20 @@ public class DataSetAndPathInfoDBConsistencyCheckTask implements IMaintenanceTas
public void execute() public void execute()
{ {
Date youngerThanDate = new Date(getTimeProvider().getTimeInMilliseconds() - timeInterval); Date youngerThanDate = new Date(getTimeProvider().getTimeInMilliseconds() - timeInterval);
List<SimpleDataSetInformationDTO> dataSets = String sessionToken = login();
getService().listOldestPhysicalDataSets(youngerThanDate, Integer.MAX_VALUE); DataSetSearchCriteria searchCriteria = new DataSetSearchCriteria();
searchCriteria.withRegistrationDate().thatIsLaterThanOrEqualTo(youngerThanDate);
searchCriteria.withPhysicalData();
DataSetFetchOptions fetchOptions = new DataSetFetchOptions();
fetchOptions.withPhysicalData();
List<DataSet> dataSets = getV3Api().searchDataSets(sessionToken, searchCriteria, fetchOptions).getObjects();
List<String> dataSetCodes = dataSets.stream()
.map(dataSet -> dataSet.getCode()).collect(Collectors.toList());
operationLog.info("Check " + dataSets.size() + " data sets registered since " operationLog.info("Check " + dataSets.size() + " data sets registered since "
+ DATE_FORMAT.format(youngerThanDate)); + DATE_FORMAT.format(youngerThanDate));
DataSetAndPathInfoDBConsistencyChecker checker = DataSetAndPathInfoDBConsistencyChecker checker =
new DataSetAndPathInfoDBConsistencyChecker(fileProvider, pathInfoProvider); new DataSetAndPathInfoDBConsistencyChecker(fileProvider, pathInfoProvider);
checker.check(dataSets); checker.checkDataSets(dataSetCodes);
if (checker.noErrorAndInconsitencyFound() == false) if (checker.noErrorAndInconsitencyFound() == false)
{ {
StringBuilder builder = new StringBuilder(); StringBuilder builder = new StringBuilder();
...@@ -104,13 +115,24 @@ public class DataSetAndPathInfoDBConsistencyCheckTask implements IMaintenanceTas ...@@ -104,13 +115,24 @@ public class DataSetAndPathInfoDBConsistencyCheckTask implements IMaintenanceTas
builder.append(checker.createReport()); builder.append(checker.createReport());
notificationLog.error(builder.toString()); notificationLog.error(builder.toString());
} }
getV3Api().logout(sessionToken);
} }
private IEncapsulatedOpenBISService getService() String login()
{
OpenBISAuthenticationInterceptor authenticationInterceptor
= ServiceProvider.getApplicationContext().getBean(OpenBISAuthenticationInterceptor.class);
String username = authenticationInterceptor.getUsername();
String password = authenticationInterceptor.getPassword();
String sessionToken = getV3Api().login(username, password);
return sessionToken;
}
private IApplicationServerApi getV3Api()
{ {
if (service == null) if (service == null)
{ {
service = ServiceProvider.getOpenBISService(); service = ServiceProvider.getV3ApplicationService();
} }
return service; return service;
} }
......
...@@ -193,6 +193,16 @@ public class OpenBISAuthenticationInterceptor implements MethodInterceptor ...@@ -193,6 +193,16 @@ public class OpenBISAuthenticationInterceptor implements MethodInterceptor
this.username = username; this.username = username;
} }
public String getUsername()
{
return username;
}
public String getPassword()
{
return password;
}
public final void setPassword(String password) public final void setPassword(String password)
{ {
this.password = password; this.password = password;
......
...@@ -21,14 +21,12 @@ import java.util.Collections; ...@@ -21,14 +21,12 @@ import java.util.Collections;
import java.util.Comparator; import java.util.Comparator;
import java.util.HashMap; import java.util.HashMap;
import java.util.HashSet; import java.util.HashSet;
import java.util.Iterator;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Map.Entry; import java.util.Map.Entry;
import java.util.Set; import java.util.Set;
import java.util.TreeMap; import java.util.TreeMap;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import java.util.stream.Stream;
import org.apache.log4j.Logger; import org.apache.log4j.Logger;
......
...@@ -32,17 +32,20 @@ import org.testng.annotations.AfterMethod; ...@@ -32,17 +32,20 @@ import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod; import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test; import org.testng.annotations.Test;
import ch.ethz.sis.openbis.generic.asapi.v3.IApplicationServerApi;
import ch.ethz.sis.openbis.generic.asapi.v3.dto.common.search.SearchResult;
import ch.ethz.sis.openbis.generic.asapi.v3.dto.dataset.DataSet;
import ch.ethz.sis.openbis.generic.asapi.v3.dto.dataset.PhysicalData;
import ch.ethz.sis.openbis.generic.asapi.v3.dto.dataset.fetchoptions.DataSetFetchOptions;
import ch.ethz.sis.openbis.generic.asapi.v3.dto.dataset.search.DataSetSearchCriteria;
import ch.systemsx.cisd.common.logging.BufferedAppender; import ch.systemsx.cisd.common.logging.BufferedAppender;
import ch.systemsx.cisd.common.test.RecordingMatcher;
import ch.systemsx.cisd.common.utilities.MockTimeProvider; import ch.systemsx.cisd.common.utilities.MockTimeProvider;
import ch.systemsx.cisd.openbis.dss.generic.server.plugins.standard.MockContent; import ch.systemsx.cisd.openbis.dss.generic.server.plugins.standard.MockContent;
import ch.systemsx.cisd.openbis.dss.generic.shared.IEncapsulatedOpenBISService;
import ch.systemsx.cisd.openbis.dss.generic.shared.IHierarchicalContentProvider; import ch.systemsx.cisd.openbis.dss.generic.shared.IHierarchicalContentProvider;
import ch.systemsx.cisd.openbis.generic.shared.basic.dto.PhysicalDataSet; import ch.systemsx.cisd.openbis.generic.shared.basic.dto.PhysicalDataSet;
import ch.systemsx.cisd.openbis.generic.shared.basic.dto.builders.DataSetBuilder; import ch.systemsx.cisd.openbis.generic.shared.basic.dto.builders.DataSetBuilder;
import ch.systemsx.cisd.openbis.generic.shared.basic.dto.builders.DataStoreBuilder; import ch.systemsx.cisd.openbis.generic.shared.basic.dto.builders.DataStoreBuilder;
import ch.systemsx.cisd.openbis.generic.shared.dto.SimpleDataSetInformationDTO;
import ch.systemsx.cisd.openbis.generic.shared.translator.DataSetTranslator;
import ch.systemsx.cisd.openbis.generic.shared.translator.SimpleDataSetHelper;
import ch.systemsx.cisd.openbis.util.LogRecordingUtils; import ch.systemsx.cisd.openbis.util.LogRecordingUtils;
/** /**
...@@ -50,11 +53,13 @@ import ch.systemsx.cisd.openbis.util.LogRecordingUtils; ...@@ -50,11 +53,13 @@ import ch.systemsx.cisd.openbis.util.LogRecordingUtils;
*/ */
public class DataSetAndPathInfoDBConsistencyCheckTaskTest extends AssertJUnit public class DataSetAndPathInfoDBConsistencyCheckTaskTest extends AssertJUnit
{ {
private static final String SESSION_TOKEN = "session-123";
private BufferedAppender logRecorder; private BufferedAppender logRecorder;
private Mockery context; private Mockery context;
private IEncapsulatedOpenBISService service; private IApplicationServerApi service;
private IHierarchicalContentProvider fileProvider; private IHierarchicalContentProvider fileProvider;
...@@ -67,12 +72,23 @@ public class DataSetAndPathInfoDBConsistencyCheckTaskTest extends AssertJUnit ...@@ -67,12 +72,23 @@ public class DataSetAndPathInfoDBConsistencyCheckTaskTest extends AssertJUnit
{ {
logRecorder = LogRecordingUtils.createRecorder("%-5p %c - %m%n", Level.INFO); logRecorder = LogRecordingUtils.createRecorder("%-5p %c - %m%n", Level.INFO);
context = new Mockery(); context = new Mockery();
service = context.mock(IEncapsulatedOpenBISService.class); service = context.mock(IApplicationServerApi.class);
fileProvider = context.mock(IHierarchicalContentProvider.class, "fileProvider"); fileProvider = context.mock(IHierarchicalContentProvider.class, "fileProvider");
pathInfoProvider = context.mock(IHierarchicalContentProvider.class, "pathInfoProvider"); pathInfoProvider = context.mock(IHierarchicalContentProvider.class, "pathInfoProvider");
task = task =
new DataSetAndPathInfoDBConsistencyCheckTask(fileProvider, pathInfoProvider, new DataSetAndPathInfoDBConsistencyCheckTask(fileProvider, pathInfoProvider,
service, new MockTimeProvider(2010, 1000)); service, new MockTimeProvider(2010, 1000)){
@Override
String login()
{
return SESSION_TOKEN;
}};
context.checking(new Expectations()
{
{
allowing(service).logout(SESSION_TOKEN);
}
});
Properties properties = new Properties(); Properties properties = new Properties();
properties.setProperty(DataSetAndPathInfoDBConsistencyCheckTask.CHECKING_TIME_INTERVAL_KEY, properties.setProperty(DataSetAndPathInfoDBConsistencyCheckTask.CHECKING_TIME_INTERVAL_KEY,
"1500 msec"); "1500 msec");
...@@ -233,21 +249,33 @@ public class DataSetAndPathInfoDBConsistencyCheckTaskTest extends AssertJUnit ...@@ -233,21 +249,33 @@ public class DataSetAndPathInfoDBConsistencyCheckTaskTest extends AssertJUnit
private void prepareListDataSets(final Date youngerThanDate, final PhysicalDataSet... dataSets) private void prepareListDataSets(final Date youngerThanDate, final PhysicalDataSet... dataSets)
{ {
final List<SimpleDataSetInformationDTO> translatedDataSets = List<DataSet> translatedDataSets = new ArrayList<DataSet>();
new ArrayList<SimpleDataSetInformationDTO>();
for (PhysicalDataSet physicalDataSet : dataSets) for (PhysicalDataSet physicalDataSet : dataSets)
{ {
translatedDataSets.add(SimpleDataSetHelper.translate(DataSetTranslator translatedDataSets.add(translate(physicalDataSet));
.translateToDescription(physicalDataSet)));
} }
context.checking(new Expectations() context.checking(new Expectations()
{ {
{ {
one(service).listOldestPhysicalDataSets(youngerThanDate, Integer.MAX_VALUE); one(service).searchDataSets(with(SESSION_TOKEN), with(new RecordingMatcher<DataSetSearchCriteria>()),
will(returnValue(translatedDataSets)); with(new RecordingMatcher<DataSetFetchOptions>()));
will(returnValue(new SearchResult<>(translatedDataSets, translatedDataSets.size())));
} }
}); });
} }
private DataSet translate(PhysicalDataSet dataSet)
{
DataSet translatedDataSet = new DataSet();
DataSetFetchOptions fetchOptions = new DataSetFetchOptions();
fetchOptions.withPhysicalData();
translatedDataSet.setFetchOptions(fetchOptions);
translatedDataSet.setCode(dataSet.getCode());
PhysicalData physicalData = new PhysicalData();
physicalData.setLocation(dataSet.getLocation());
translatedDataSet.setPhysicalData(physicalData);
return translatedDataSet;
}
private DataSetBuilder createDataSetBuilder() private DataSetBuilder createDataSetBuilder()
{ {
......
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