Issue #2361 Centralized serialization to the HarvesterConfigurationManager.
Former-commit-id:15aed68c02
[formerly6cb541d1a1
[formerly ded6bbf39f6d6fe05f31d61f310e7473d55a6643]] Former-commit-id:6cb541d1a1
Former-commit-id:f5b9d3be39
This commit is contained in:
parent
a608282545
commit
91e69b800d
7 changed files with 61 additions and 42 deletions
|
@ -20,6 +20,7 @@ package com.raytheon.uf.common.datadelivery.harvester;
|
||||||
* further licensing information.
|
* further licensing information.
|
||||||
**/
|
**/
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
@ -79,13 +80,7 @@ public class HarvesterConfigurationManager {
|
||||||
|
|
||||||
for (LocalizationFile lf : getLocalizedFiles()) {
|
for (LocalizationFile lf : getLocalizedFiles()) {
|
||||||
|
|
||||||
try {
|
config = getHarvesterFile(lf.getFile());
|
||||||
config = HarvesterJaxbManager.getJaxb().unmarshalFromXmlFile(HarvesterConfig.class, lf.getFile());
|
|
||||||
} catch (SerializationException e) {
|
|
||||||
statusHandler.handle(Priority.ERROR,
|
|
||||||
"Can't deserialize harvester config at "
|
|
||||||
+ lf.getFile().getPath(), e);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (config != null) {
|
if (config != null) {
|
||||||
Agent agent = config.getAgent();
|
Agent agent = config.getAgent();
|
||||||
|
@ -110,13 +105,7 @@ public class HarvesterConfigurationManager {
|
||||||
|
|
||||||
for (LocalizationFile lf : getLocalizedFiles()) {
|
for (LocalizationFile lf : getLocalizedFiles()) {
|
||||||
|
|
||||||
try {
|
config = getHarvesterFile(lf.getFile());
|
||||||
config = HarvesterJaxbManager.getJaxb().unmarshalFromXmlFile(HarvesterConfig.class, lf.getFile());
|
|
||||||
} catch (SerializationException e) {
|
|
||||||
statusHandler.handle(Priority.ERROR,
|
|
||||||
"Can't deserialize harvester config at "
|
|
||||||
+ lf.getFile().getPath(), e);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (config != null) {
|
if (config != null) {
|
||||||
Agent agent = config.getAgent();
|
Agent agent = config.getAgent();
|
||||||
|
@ -132,4 +121,39 @@ public class HarvesterConfigurationManager {
|
||||||
return config;
|
return config;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get this harvester configuration File
|
||||||
|
* @param file
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public static HarvesterConfig getHarvesterFile(File file) {
|
||||||
|
|
||||||
|
HarvesterConfig config = null;
|
||||||
|
|
||||||
|
try {
|
||||||
|
config = HarvesterJaxbManager.getJaxb().unmarshalFromXmlFile(HarvesterConfig.class, file);
|
||||||
|
} catch (SerializationException e) {
|
||||||
|
statusHandler.handle(Priority.ERROR,
|
||||||
|
"Can't deserialize harvester config at "
|
||||||
|
+ file.getPath(), e);
|
||||||
|
}
|
||||||
|
|
||||||
|
return config;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Writes the harvester config files
|
||||||
|
* @param config
|
||||||
|
* @param file
|
||||||
|
*/
|
||||||
|
public static void setHarvesterFile(HarvesterConfig config, File file) {
|
||||||
|
try {
|
||||||
|
HarvesterJaxbManager.getJaxb().marshalToXmlFile(config,
|
||||||
|
file.getAbsolutePath());
|
||||||
|
} catch (SerializationException e) {
|
||||||
|
statusHandler.handle(Priority.ERROR, "Couldn't write Harvester Config file.", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,7 +15,7 @@ import java.util.Set;
|
||||||
import com.raytheon.uf.common.datadelivery.harvester.Agent;
|
import com.raytheon.uf.common.datadelivery.harvester.Agent;
|
||||||
import com.raytheon.uf.common.datadelivery.harvester.CrawlAgent;
|
import com.raytheon.uf.common.datadelivery.harvester.CrawlAgent;
|
||||||
import com.raytheon.uf.common.datadelivery.harvester.HarvesterConfig;
|
import com.raytheon.uf.common.datadelivery.harvester.HarvesterConfig;
|
||||||
import com.raytheon.uf.common.datadelivery.harvester.HarvesterJaxbManager;
|
import com.raytheon.uf.common.datadelivery.harvester.HarvesterConfigurationManager;
|
||||||
import com.raytheon.uf.common.datadelivery.registry.Collection;
|
import com.raytheon.uf.common.datadelivery.registry.Collection;
|
||||||
import com.raytheon.uf.common.datadelivery.registry.Provider;
|
import com.raytheon.uf.common.datadelivery.registry.Provider;
|
||||||
import com.raytheon.uf.common.datadelivery.registry.Utils;
|
import com.raytheon.uf.common.datadelivery.registry.Utils;
|
||||||
|
@ -99,9 +99,9 @@ public class CrawlMetaDataHandler implements RegistryInitializedListener {
|
||||||
|
|
||||||
if (files != null) {
|
if (files != null) {
|
||||||
for (LocalizationFile file : files) {
|
for (LocalizationFile file : files) {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
HarvesterConfig hc = HarvesterJaxbManager.getJaxb().unmarshalFromXmlFile(HarvesterConfig.class, file.getFile());
|
HarvesterConfig hc = HarvesterConfigurationManager
|
||||||
|
.getHarvesterFile(file.getFile());
|
||||||
Agent agent = hc.getAgent();
|
Agent agent = hc.getAgent();
|
||||||
|
|
||||||
if (agent != null) {
|
if (agent != null) {
|
||||||
|
|
|
@ -12,7 +12,7 @@ import org.quartz.JobExecutionException;
|
||||||
import com.raytheon.uf.common.datadelivery.harvester.Agent;
|
import com.raytheon.uf.common.datadelivery.harvester.Agent;
|
||||||
import com.raytheon.uf.common.datadelivery.harvester.CrawlAgent;
|
import com.raytheon.uf.common.datadelivery.harvester.CrawlAgent;
|
||||||
import com.raytheon.uf.common.datadelivery.harvester.HarvesterConfig;
|
import com.raytheon.uf.common.datadelivery.harvester.HarvesterConfig;
|
||||||
import com.raytheon.uf.common.datadelivery.harvester.HarvesterJaxbManager;
|
import com.raytheon.uf.common.datadelivery.harvester.HarvesterConfigurationManager;
|
||||||
import com.raytheon.uf.common.localization.IPathManager;
|
import com.raytheon.uf.common.localization.IPathManager;
|
||||||
import com.raytheon.uf.common.localization.LocalizationContext;
|
import com.raytheon.uf.common.localization.LocalizationContext;
|
||||||
import com.raytheon.uf.common.localization.LocalizationContext.LocalizationLevel;
|
import com.raytheon.uf.common.localization.LocalizationContext.LocalizationLevel;
|
||||||
|
@ -143,9 +143,10 @@ public abstract class CrawlLauncher implements Job {
|
||||||
|
|
||||||
if (files != null) {
|
if (files != null) {
|
||||||
for (LocalizationFile lf : files) {
|
for (LocalizationFile lf : files) {
|
||||||
HarvesterConfig hc = HarvesterJaxbManager.getJaxb()
|
|
||||||
.unmarshalFromXmlFile(HarvesterConfig.class,
|
HarvesterConfig hc = HarvesterConfigurationManager
|
||||||
lf.getFile());
|
.getHarvesterFile(lf.getFile());
|
||||||
|
|
||||||
if (hc.getAgent() != null) {
|
if (hc.getAgent() != null) {
|
||||||
// we only want crawler types for CrawlerMetadata
|
// we only want crawler types for CrawlerMetadata
|
||||||
Agent agent = hc.getAgent();
|
Agent agent = hc.getAgent();
|
||||||
|
|
|
@ -16,6 +16,7 @@ import com.raytheon.edex.util.Util;
|
||||||
import com.raytheon.uf.common.comm.ProxyConfiguration;
|
import com.raytheon.uf.common.comm.ProxyConfiguration;
|
||||||
import com.raytheon.uf.common.datadelivery.harvester.CrawlAgent;
|
import com.raytheon.uf.common.datadelivery.harvester.CrawlAgent;
|
||||||
import com.raytheon.uf.common.datadelivery.harvester.HarvesterConfig;
|
import com.raytheon.uf.common.datadelivery.harvester.HarvesterConfig;
|
||||||
|
import com.raytheon.uf.common.datadelivery.harvester.HarvesterConfigurationManager;
|
||||||
import com.raytheon.uf.common.datadelivery.harvester.HarvesterJaxbManager;
|
import com.raytheon.uf.common.datadelivery.harvester.HarvesterJaxbManager;
|
||||||
import com.raytheon.uf.common.datadelivery.registry.Collection;
|
import com.raytheon.uf.common.datadelivery.registry.Collection;
|
||||||
import com.raytheon.uf.common.serialization.SerializationException;
|
import com.raytheon.uf.common.serialization.SerializationException;
|
||||||
|
@ -139,10 +140,9 @@ public abstract class Crawler {
|
||||||
HarvesterConfig hc = null;
|
HarvesterConfig hc = null;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
hc = HarvesterJaxbManager.getJaxb().unmarshalFromXmlFile(
|
hc = HarvesterConfigurationManager.getHarvesterFile(configFile);
|
||||||
HarvesterConfig.class, configFile);
|
} catch (Exception e1) {
|
||||||
} catch (SerializationException e1) {
|
statusHandler.handle(Priority.ERROR, e1.getLocalizedMessage(), e1);
|
||||||
e1.printStackTrace();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return hc;
|
return hc;
|
||||||
|
|
|
@ -34,7 +34,7 @@ import java.util.regex.Pattern;
|
||||||
import com.google.common.annotations.VisibleForTesting;
|
import com.google.common.annotations.VisibleForTesting;
|
||||||
import com.raytheon.uf.common.datadelivery.harvester.CrawlAgent;
|
import com.raytheon.uf.common.datadelivery.harvester.CrawlAgent;
|
||||||
import com.raytheon.uf.common.datadelivery.harvester.HarvesterConfig;
|
import com.raytheon.uf.common.datadelivery.harvester.HarvesterConfig;
|
||||||
import com.raytheon.uf.common.datadelivery.harvester.HarvesterJaxbManager;
|
import com.raytheon.uf.common.datadelivery.harvester.HarvesterConfigurationManager;
|
||||||
import com.raytheon.uf.common.datadelivery.harvester.ProtoCollection;
|
import com.raytheon.uf.common.datadelivery.harvester.ProtoCollection;
|
||||||
import com.raytheon.uf.common.datadelivery.registry.Collection;
|
import com.raytheon.uf.common.datadelivery.registry.Collection;
|
||||||
import com.raytheon.uf.common.datadelivery.registry.Provider;
|
import com.raytheon.uf.common.datadelivery.registry.Provider;
|
||||||
|
@ -44,7 +44,6 @@ import com.raytheon.uf.common.localization.LocalizationContext.LocalizationLevel
|
||||||
import com.raytheon.uf.common.localization.LocalizationContext.LocalizationType;
|
import com.raytheon.uf.common.localization.LocalizationContext.LocalizationType;
|
||||||
import com.raytheon.uf.common.localization.LocalizationFile;
|
import com.raytheon.uf.common.localization.LocalizationFile;
|
||||||
import com.raytheon.uf.common.localization.PathManagerFactory;
|
import com.raytheon.uf.common.localization.PathManagerFactory;
|
||||||
import com.raytheon.uf.common.localization.exception.LocalizationOpFailedException;
|
|
||||||
import com.raytheon.uf.common.serialization.ExceptionWrapper;
|
import com.raytheon.uf.common.serialization.ExceptionWrapper;
|
||||||
import com.raytheon.uf.common.serialization.SerializableExceptionWrapper;
|
import com.raytheon.uf.common.serialization.SerializableExceptionWrapper;
|
||||||
import com.raytheon.uf.common.serialization.SerializationException;
|
import com.raytheon.uf.common.serialization.SerializationException;
|
||||||
|
@ -74,7 +73,7 @@ import com.raytheon.uf.edex.datadelivery.retrieval.ProviderCollectionLinkStore;
|
||||||
* Aug 06, 2012 1022 djohnson Add shutdown(), write out millis with filename to prevent overwriting.
|
* Aug 06, 2012 1022 djohnson Add shutdown(), write out millis with filename to prevent overwriting.
|
||||||
* Sep 10, 2012 1154 djohnson Use JAXB instead of thrift, allowing introspection of links, return files in ascending order.
|
* Sep 10, 2012 1154 djohnson Use JAXB instead of thrift, allowing introspection of links, return files in ascending order.
|
||||||
* Mar 14, 2013 1794 djohnson Consolidate common FilenameFilter implementations.
|
* Mar 14, 2013 1794 djohnson Consolidate common FilenameFilter implementations.
|
||||||
* Oct 28, 2013 2361 dhladky Fixed up JAXBManager.
|
* * Oct 28, 2013 2361 dhladky Fixed up JAXBManager.
|
||||||
*
|
*
|
||||||
* </pre>
|
* </pre>
|
||||||
*
|
*
|
||||||
|
@ -375,17 +374,14 @@ class FileCommunicationStrategy implements CommunicationStrategy {
|
||||||
File file = lf.getFile();
|
File file = lf.getFile();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
HarvesterJaxbManager.getJaxb().marshalToXmlFile(hconfig,
|
HarvesterConfigurationManager.setHarvesterFile(hconfig, file);
|
||||||
file.getAbsolutePath());
|
|
||||||
lf.save();
|
lf.save();
|
||||||
} catch (SerializationException e) {
|
} catch (Exception e) {
|
||||||
statusHandler
|
statusHandler
|
||||||
.error("Unable to recreate the "
|
.error("Unable to recreate the "
|
||||||
+ provider
|
+ provider
|
||||||
+ "-harvester.xml configuration! Save of new collections failed",
|
+ "-harvester.xml configuration! Save of new collections failed",
|
||||||
e);
|
e);
|
||||||
} catch (LocalizationOpFailedException e) {
|
|
||||||
statusHandler.handle(Priority.ERROR, e.getLocalizedMessage(), e);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -6,7 +6,7 @@ import java.util.List;
|
||||||
import com.raytheon.uf.common.datadelivery.harvester.Agent;
|
import com.raytheon.uf.common.datadelivery.harvester.Agent;
|
||||||
import com.raytheon.uf.common.datadelivery.harvester.CrawlAgent;
|
import com.raytheon.uf.common.datadelivery.harvester.CrawlAgent;
|
||||||
import com.raytheon.uf.common.datadelivery.harvester.HarvesterConfig;
|
import com.raytheon.uf.common.datadelivery.harvester.HarvesterConfig;
|
||||||
import com.raytheon.uf.common.datadelivery.harvester.HarvesterJaxbManager;
|
import com.raytheon.uf.common.datadelivery.harvester.HarvesterConfigurationManager;
|
||||||
import com.raytheon.uf.common.localization.IPathManager;
|
import com.raytheon.uf.common.localization.IPathManager;
|
||||||
import com.raytheon.uf.common.localization.LocalizationContext;
|
import com.raytheon.uf.common.localization.LocalizationContext;
|
||||||
import com.raytheon.uf.common.localization.LocalizationContext.LocalizationLevel;
|
import com.raytheon.uf.common.localization.LocalizationContext.LocalizationLevel;
|
||||||
|
@ -79,9 +79,9 @@ public class MainSequenceCrawlLauncher extends CrawlLauncher {
|
||||||
// if many, start many
|
// if many, start many
|
||||||
for (LocalizationFile lf : getLocalizedFiles()) {
|
for (LocalizationFile lf : getLocalizedFiles()) {
|
||||||
|
|
||||||
HarvesterConfig hc = HarvesterJaxbManager.getJaxb()
|
HarvesterConfig hc = HarvesterConfigurationManager
|
||||||
.unmarshalFromXmlFile(HarvesterConfig.class,
|
.getHarvesterFile(lf.getFile());
|
||||||
lf.getFile());
|
|
||||||
if (hc.getProvider().getName().equals(providerName)) {
|
if (hc.getProvider().getName().equals(providerName)) {
|
||||||
if (hc.getAgent() != null) {
|
if (hc.getAgent() != null) {
|
||||||
// we only want crawler types for CrawlerMetadata
|
// we only want crawler types for CrawlerMetadata
|
||||||
|
|
|
@ -6,7 +6,7 @@ import java.util.List;
|
||||||
import com.raytheon.uf.common.datadelivery.harvester.Agent;
|
import com.raytheon.uf.common.datadelivery.harvester.Agent;
|
||||||
import com.raytheon.uf.common.datadelivery.harvester.CrawlAgent;
|
import com.raytheon.uf.common.datadelivery.harvester.CrawlAgent;
|
||||||
import com.raytheon.uf.common.datadelivery.harvester.HarvesterConfig;
|
import com.raytheon.uf.common.datadelivery.harvester.HarvesterConfig;
|
||||||
import com.raytheon.uf.common.datadelivery.harvester.HarvesterJaxbManager;
|
import com.raytheon.uf.common.datadelivery.harvester.HarvesterConfigurationManager;
|
||||||
import com.raytheon.uf.common.localization.IPathManager;
|
import com.raytheon.uf.common.localization.IPathManager;
|
||||||
import com.raytheon.uf.common.localization.LocalizationContext;
|
import com.raytheon.uf.common.localization.LocalizationContext;
|
||||||
import com.raytheon.uf.common.localization.LocalizationContext.LocalizationLevel;
|
import com.raytheon.uf.common.localization.LocalizationContext.LocalizationLevel;
|
||||||
|
@ -77,9 +77,7 @@ public class SeedCrawlLauncher extends CrawlLauncher {
|
||||||
// if many, start many
|
// if many, start many
|
||||||
for (LocalizationFile lf : getLocalizedFiles()) {
|
for (LocalizationFile lf : getLocalizedFiles()) {
|
||||||
|
|
||||||
HarvesterConfig hc = HarvesterJaxbManager.getJaxb()
|
HarvesterConfig hc = HarvesterConfigurationManager.getHarvesterFile(lf.getFile());
|
||||||
.unmarshalFromXmlFile(HarvesterConfig.class,
|
|
||||||
lf.getFile());
|
|
||||||
|
|
||||||
if (hc.getProvider().getName().equals(providerName)) {
|
if (hc.getProvider().getName().equals(providerName)) {
|
||||||
if (hc.getAgent() != null) {
|
if (hc.getAgent() != null) {
|
||||||
|
|
Loading…
Add table
Reference in a new issue