org.lockss.ws.status.DaemonStatusServiceImpl Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of laaws-soap-service Show documentation
Show all versions of laaws-soap-service Show documentation
LOCKSS SOAP Compatibility Service
/*
Copyright (c) 2013-2020 Board of Trustees of Leland Stanford Jr. University,
all rights reserved.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
STANFORD UNIVERSITY BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR
IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Except as contained in this notice, the name of Stanford University shall not
be used in advertising or otherwise to promote the sale, use or other dealings
in this Software without prior written authorization from Stanford University.
*/
package org.lockss.ws.status;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.lockss.laaws.rs.model.Artifact;
import org.lockss.log.L4JLogger;
import org.lockss.util.rest.exception.LockssRestException;
import org.lockss.util.rest.poller.RestPollerClient;
import org.lockss.util.rest.status.RestStatusClient;
import org.lockss.ws.BaseServiceImpl;
import org.lockss.ws.entities.AuStatus;
import org.lockss.ws.entities.AuWsResult;
import org.lockss.ws.entities.CrawlWsResult;
import org.lockss.ws.entities.IdNamePair;
import org.lockss.ws.entities.LockssWebServicesFault;
import org.lockss.ws.entities.PeerWsResult;
import org.lockss.ws.entities.PlatformConfigurationWsResult;
import org.lockss.ws.entities.PluginWsResult;
import org.lockss.ws.entities.PollWsResult;
import org.lockss.ws.entities.RepositorySpaceWsResult;
import org.lockss.ws.entities.RepositoryWsResult;
import org.lockss.ws.entities.TdbAuWsResult;
import org.lockss.ws.entities.TdbPublisherWsResult;
import org.lockss.ws.entities.TdbTitleWsResult;
import org.lockss.ws.entities.VoteWsResult;
import org.lockss.ws.status.DaemonStatusService;
import org.springframework.http.HttpMethod;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Service;
/**
* The Daemon Status SOAP web service implementation.
*/
@Service
public class DaemonStatusServiceImpl extends BaseServiceImpl
implements DaemonStatusService {
private final static L4JLogger log = L4JLogger.getLogger();
/**
* Provides an indication of whether the daemon is ready.
*
* @return a boolean with the indication.
* @throws LockssWebServicesFault if there are problems.
*/
@Override
public boolean isDaemonReady() throws LockssWebServicesFault {
log.debug2("Invoked.");
try {
boolean result = true;
// Check the repository service.
String url = env.getProperty(REPO_SVC_URL_KEY);
if (url != null) {
result = isServiceReady(url);
if (!result) {
log.debug2("result = {}", result);
return result;
}
}
// Check the configuration service.
url = env.getProperty(CONFIG_SVC_URL_KEY);
if (url != null) {
result = isServiceReady(url);
if (!result) {
log.debug2("result = {}", result);
return result;
}
}
// Check the poller service.
url = env.getProperty(POLLER_SVC_URL_KEY);
if (url != null) {
result = isServiceReady(url);
if (!result) {
log.debug2("result = {}", result);
return result;
}
}
// Check the metadata extractor service.
url = env.getProperty(MDX_SVC_URL_KEY);
if (url != null) {
result = isServiceReady(url);
if (!result) {
log.debug2("result = {}", result);
return result;
}
}
// Check the metadata service.
url = env.getProperty(MDQ_SVC_URL_KEY);
if (url != null) {
result = isServiceReady(url);
}
log.debug2("result = {}", result);
return result;
} catch (Exception e) {
throw new LockssWebServicesFault(e);
}
}
/**
* Provides an indication of whether a REST service is ready.
*
* @param serviceUrl A String with the URL of the service.
* @return a boolean with the indication.
*/
private boolean isServiceReady(String serviceUrl) {
log.debug2("serviceUrl = {}", serviceUrl);
boolean isReady = false;
try {
isReady = new RestStatusClient(serviceUrl).getStatus().isReady();
} catch (LockssRestException lre) {
log.debug("Ignored exception caught getting status of " + serviceUrl,
lre);
}
log.debug2("isReady = {}", isReady);
return isReady;
}
/**
* Provides a list of the identifier/name pairs of the archival units in the
* system.
*
* @return a {@code List} with the identifier/name pairs of the
* archival units in the system.
* @throws LockssWebServicesFault if there are problems.
*/
@Override
public Collection getAuIds() throws LockssWebServicesFault {
log.debug2("Invoked.");
// Get the requested information via the queryAus SOAP operation.
List queryAusResult = queryAus("select auId, name");
log.trace("queryAusResult = {}", queryAusResult);
try {
// Initialize the results.
Collection results = new ArrayList<>(queryAusResult.size());
// Loop through the results of the queryAus SOAP operation.
for (AuWsResult auWsResult : queryAusResult) {
// Populate the results.
results.add(new IdNamePair(auWsResult.getAuId(), auWsResult.getName()));
}
log.debug2("results = {}", results);
return results;
} catch (Exception e) {
throw new LockssWebServicesFault(e);
}
}
/**
* Provides the status information of an archival unit in the system.
*
* @param auId A String with the identifier of the archival unit.
* @return an AuStatus with the status information of the archival unit.
* @throws LockssWebServicesFault if there are problems.
*/
@Override
public AuStatus getAuStatus(String auId) throws LockssWebServicesFault {
log.debug2("auId = {}", auId);
try {
// Prepare the URI path variables.
Map uriVariables = new HashMap<>(1);
uriVariables.put("auId", auId);
log.trace("uriVariables = {}", uriVariables);
// Make the REST call.
ResponseEntity response = callRestServiceEndpoint(
env.getProperty(CONFIG_SVC_URL_KEY), "/austatuses/{auId}",
uriVariables, null, HttpMethod.GET, (Void)null,
"Can't get AU status");
// Get the response body.
try {
ObjectMapper mapper = new ObjectMapper();
AuStatus result = mapper.readValue(response.getBody(), AuStatus.class);
log.debug2("result = " + result);
return result;
} catch (Exception e) {
log.error("Cannot get body of response", e);
throw e;
}
} catch (Exception e) {
throw new LockssWebServicesFault(e);
}
}
/**
* Provides the selected properties of selected plugins in the system.
*
* @param pluginQuery A String with the
* SQL-like
* query used to specify what properties to retrieve
* from which plugins.
* @return a {@code List} with the results.
* @throws LockssWebServicesFault if there are problems.
*/
@Override
public List queryPlugins(String pluginQuery)
throws LockssWebServicesFault {
log.debug2("pluginQuery = {}", pluginQuery);
try {
// Prepare the query parameters.
Map queryParams = new HashMap<>(1);
queryParams.put("pluginQuery", pluginQuery);
log.trace("queryParams = {}", queryParams);
// Make the REST call.
ResponseEntity response = callRestServiceEndpoint(
env.getProperty(CONFIG_SVC_URL_KEY), "/plugins", null, queryParams,
HttpMethod.GET, (Void)null, "Can't query plugins");
// Get the response body.
try {
ObjectMapper mapper = new ObjectMapper();
List result = mapper.readValue(response.getBody(),
new TypeReference>(){});
log.debug2("result = " + result);
return result;
} catch (Exception e) {
log.error("Cannot get body of response", e);
throw e;
}
} catch (Exception e) {
throw new LockssWebServicesFault(e);
}
}
/**
* Provides the selected properties of selected archival units in the system.
*
* @param auQuery A String with the
* SQL-like
* query used to specify what properties to retrieve from
* which archival units.
* @return a {@code List} with the results.
* @throws LockssWebServicesFault if there are problems.
*/
@Override
public List queryAus(String auQuery) throws LockssWebServicesFault
{
log.debug2("auQuery = {}", auQuery);
try {
// Prepare the query parameters.
Map queryParams = new HashMap<>(1);
queryParams.put("auQuery", auQuery);
log.trace("queryParams = {}", queryParams);
// Make the REST call.
ResponseEntity response = callRestServiceEndpoint(
env.getProperty(CONFIG_SVC_URL_KEY), "/auqueries", null, queryParams,
HttpMethod.GET, (Void)null, "Can't query AUs");
// Get the response body.
try {
ObjectMapper mapper = new ObjectMapper();
List result = mapper.readValue(response.getBody(),
new TypeReference>(){});
log.debug2("result = " + result);
return result;
} catch (Exception e) {
log.error("Cannot get body of response", e);
throw e;
}
} catch (Exception e) {
throw new LockssWebServicesFault(e);
}
}
/**
* Provides the selected properties of selected peers in the system.
*
* @param peerQuery A String with the
* SQL-like
* query used to specify what properties to retrieve from
* which peers.
* @return a {@code List} with the results.
* @throws LockssWebServicesFault if there are problems.
*/
@Override
public List queryPeers(String peerQuery)
throws LockssWebServicesFault {
log.debug2("peerQuery = {}", peerQuery);
try {
// Make the REST call to make the query.
List results =
new RestPollerClient(env.getProperty(POLLER_SVC_URL_KEY),
getSoapRequestAuthorizationHeader()).queryPeers(peerQuery);
log.debug2("results = {}", results);
return results;
} catch (Exception e) {
throw new LockssWebServicesFault(e);
}
}
/**
* Provides the selected properties of selected votes in the system.
*
* @param voteQuery A String with the
* SQL-like
* query used to specify what properties to retrieve from
* which votes.
* @return a {@code List} with the results.
* @throws LockssWebServicesFault if there are problems.
*/
@Override
public List queryVotes(String voteQuery)
throws LockssWebServicesFault {
log.debug2("voteQuery = {}", voteQuery);
try {
// Make the REST call to make the query.
List results =
new RestPollerClient(env.getProperty(POLLER_SVC_URL_KEY),
getSoapRequestAuthorizationHeader()).queryVotes(voteQuery);
log.debug2("results = {}", results);
return results;
} catch (Exception e) {
throw new LockssWebServicesFault(e);
}
}
/**
* Provides the selected properties of selected repository spaces in the
* system.
* @param repositorySpaceQuery A String with the SQL-like
* query used to specify what properties to
* retrieve from which repository spaces.
* @return a {@code List} with the results.
* @throws LockssWebServicesFault if there are problems.
*/
@Override
public List queryRepositorySpaces(
String repositorySpaceQuery) throws LockssWebServicesFault {
log.debug2("repositorySpaceQuery = {}", repositorySpaceQuery);
try {
// Make the REST call to make the query.
List results =
new RestPollerClient(env.getProperty(POLLER_SVC_URL_KEY),
getSoapRequestAuthorizationHeader())
.queryRepositorySpaces(repositorySpaceQuery);
log.debug2("results = {}", results);
return results;
} catch (Exception e) {
throw new LockssWebServicesFault(e);
}
}
/**
* Provides the selected properties of selected repositories in the system.
*
* @param repositoryQuery A String with the
*
* SQL-like query used to specify what properties
* to retrieve from which repositories.
* @return a {@code List} with the results.
* @throws LockssWebServicesFault if there are problems.
*/
@Override
public List queryRepositories(String repositoryQuery)
throws LockssWebServicesFault {
log.debug2("repositoryQuery = {}", repositoryQuery);
try {
// Make the REST call to make the query.
List results =
new RestPollerClient(env.getProperty(POLLER_SVC_URL_KEY),
getSoapRequestAuthorizationHeader())
.queryRepositories(repositoryQuery);
log.debug2("results = {}", results);
return results;
} catch (Exception e) {
throw new LockssWebServicesFault(e);
}
}
/**
* Provides the selected properties of selected crawls in the system.
*
* @param crawlQuery A String with the
* SQL-like
* query used to specify what properties to retrieve
* from which crawls.
* @return a {@code List} with the results.
* @throws LockssWebServicesFault if there are problems.
*/
@Override
public List queryCrawls(String crawlQuery)
throws LockssWebServicesFault {
log.debug2("crawlQuery = {}", crawlQuery);
try {
// TODO: REPLACE THIS BLOCK WITH THE ACTUAL IMPLEMENTATION.
List results = new ArrayList<>();
// TODO: END OF BLOCK TO BE REPLACED.
log.debug2("results = {}", results);
return results;
} catch (Exception e) {
throw new LockssWebServicesFault(e);
}
}
/**
* Provides the selected properties of selected polls in the system.
*
* @param pollQuery A String with the
* SQL-like
* query used to specify what properties to retrieve from
* which polls.
* @return a {@code List} with the results.
* @throws LockssWebServicesFault if there are problems.
*/
@Override
public List queryPolls(String pollQuery)
throws LockssWebServicesFault {
log.debug2("pollQuery = {}", pollQuery);
try {
// Make the REST call to make the query.
List results =
new RestPollerClient(env.getProperty(POLLER_SVC_URL_KEY),
getSoapRequestAuthorizationHeader()).queryPolls(pollQuery);
log.debug2("results = {}", results);
return results;
} catch (Exception e) {
throw new LockssWebServicesFault(e);
}
}
/**
* Provides the platform configuration.
*
* @return a PlatformConfigurationWsResult with the platform configuration.
* @throws LockssWebServicesFault if there are problems.
*/
@Override
public PlatformConfigurationWsResult getPlatformConfiguration()
throws LockssWebServicesFault {
log.debug2("Invoked.");
try {
// Make the REST call.
ResponseEntity response = callRestServiceEndpoint(
env.getProperty(CONFIG_SVC_URL_KEY), "/config/platform", null, null,
HttpMethod.GET, (Void)null, "Can't get platform configuration");
// Get the response body.
try {
ObjectMapper mapper = new ObjectMapper();
PlatformConfigurationWsResult result = mapper.readValue(
response.getBody(), PlatformConfigurationWsResult.class);
log.debug2("result = " + result);
return result;
} catch (Exception e) {
log.error("Cannot get body of response", e);
throw e;
}
} catch (Exception e) {
throw new LockssWebServicesFault(e);
}
}
/**
* Provides the selected properties of selected title database publishers.
*
* @param tdbPublisherQuery A String with the SQL-like
* query used to specify what properties to
* retrieve from which title database publishers.
* @return a {@code List} with the results.
* @throws LockssWebServicesFault if there are problems.
*/
@Override
public List queryTdbPublishers(String tdbPublisherQuery)
throws LockssWebServicesFault {
log.debug2("tdbPublisherQuery = {}", tdbPublisherQuery);
try {
// Prepare the query parameters.
Map queryParams = new HashMap<>(1);
queryParams.put("tdbPublisherQuery", tdbPublisherQuery);
log.trace("queryParams = {}", queryParams);
// Make the REST call.
ResponseEntity response = callRestServiceEndpoint(
env.getProperty(CONFIG_SVC_URL_KEY), "/tdbpublishers", null,
queryParams, HttpMethod.GET, (Void)null,
"Can't query TDB publishers");
// Get the response body.
try {
ObjectMapper mapper = new ObjectMapper();
List result = mapper.readValue(response.getBody(),
new TypeReference>(){});
log.debug2("result = " + result);
return result;
} catch (Exception e) {
log.error("Cannot get body of response", e);
throw e;
}
} catch (Exception e) {
throw new LockssWebServicesFault(e);
}
}
/**
* Provides the selected properties of selected title database titles.
*
* @param tdbTitleQuery A String with the
* SQL-like
* query used to specify what properties to retrieve
* from which title database titles.
* @return a {@code List} with the results.
* @throws LockssWebServicesFault if there are problems.
*/
@Override
public List queryTdbTitles(String tdbTitleQuery)
throws LockssWebServicesFault {
log.debug2("tdbTitleQuery = {}", tdbTitleQuery);
try {
// Prepare the query parameters.
Map queryParams = new HashMap<>(1);
queryParams.put("tdbTitleQuery", tdbTitleQuery);
log.trace("queryParams = {}", queryParams);
// Make the REST call.
ResponseEntity response = callRestServiceEndpoint(
env.getProperty(CONFIG_SVC_URL_KEY), "/tdbtitles", null, queryParams,
HttpMethod.GET, (Void)null, "Can't query TDB titles");
// Get the response body.
try {
ObjectMapper mapper = new ObjectMapper();
List result = mapper.readValue(response.getBody(),
new TypeReference>(){});
log.debug2("result = " + result);
return result;
} catch (Exception e) {
log.error("Cannot get body of response", e);
throw e;
}
} catch (Exception e) {
throw new LockssWebServicesFault(e);
}
}
/**
* Provides the selected properties of selected title database archival units.
*
* @param tdbAuQuery A String with the
* SQL-like
* query used to specify what properties to retrieve
* from which title database archival units.
* @return a {@code List} with the results.
* @throws LockssWebServicesFault if there are problems.
*/
@Override
public List queryTdbAus(String tdbAuQuery)
throws LockssWebServicesFault {
log.debug2("tdbAuQuery = {}", tdbAuQuery);
try {
// Prepare the query parameters.
Map queryParams = new HashMap<>(1);
queryParams.put("tdbAuQuery", tdbAuQuery);
log.trace("queryParams = {}", queryParams);
// Make the REST call.
ResponseEntity response = callRestServiceEndpoint(
env.getProperty(CONFIG_SVC_URL_KEY), "/tdbaus", null, queryParams,
HttpMethod.GET, (Void)null, "Can't query TDB AUs");
// Get the response body.
try {
ObjectMapper mapper = new ObjectMapper();
List result = mapper.readValue(response.getBody(),
new TypeReference>(){});
log.debug2("result = " + result);
return result;
} catch (Exception e) {
log.error("Cannot get body of response", e);
throw e;
}
} catch (Exception e) {
throw new LockssWebServicesFault(e);
}
}
/**
* Provides the URLs in an archival unit.
*
* @param auId A String with the identifier of the archival unit.
* @param url A String with the URL above which no results will be provided,
* or NULL
if all the URLS are to be provided.
* @return a {@code List} with the results.
* @throws LockssWebServicesFault if there are problems.
*/
public List getAuUrls(String auId, String url)
throws LockssWebServicesFault {
log.debug2("auId = {}", auId);
log.debug2("url = {}", url);
try {
List results = new ArrayList<>();
String prefixUrl = url == null ? "" : url;
log.trace("prefixUrl = {}", prefixUrl);
// Loop through all the artifacts in the response from the REST service.
for (Artifact artifact : getRestLockssRepository().
getArtifactsWithPrefix(env.getProperty(REPO_COLLECTION_KEY), auId,
prefixUrl)) {
log.trace("artifact = {}", artifact);
// Add this artifact URL to the results.
results.add(artifact.getUri());
}
log.debug2("results = {}", results);
return results;
} catch (Exception e) {
throw new LockssWebServicesFault(e);
}
}
}