You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@uima.apache.org by bu...@apache.org on 2018/12/21 22:00:22 UTC
svn commit: r1849499 - in
/uima/uima-ducc/trunk/uima-ducc-pullservice/src/main/java/org/apache/uima/ducc/ps/service:
ServiceConfiguration.java dgen/DeployableGenerator.java
main/PullService.java main/ServiceWrapper.java
Author: burn
Date: Fri Dec 21 22:00:22 2018
New Revision: 1849499
URL: http://svn.apache.org/viewvc?rev=1849499&view=rev
Log:
UIMA-5941 Remove unused imports
Modified:
uima/uima-ducc/trunk/uima-ducc-pullservice/src/main/java/org/apache/uima/ducc/ps/service/ServiceConfiguration.java
uima/uima-ducc/trunk/uima-ducc-pullservice/src/main/java/org/apache/uima/ducc/ps/service/dgen/DeployableGenerator.java
uima/uima-ducc/trunk/uima-ducc-pullservice/src/main/java/org/apache/uima/ducc/ps/service/main/PullService.java
uima/uima-ducc/trunk/uima-ducc-pullservice/src/main/java/org/apache/uima/ducc/ps/service/main/ServiceWrapper.java
Modified: uima/uima-ducc/trunk/uima-ducc-pullservice/src/main/java/org/apache/uima/ducc/ps/service/ServiceConfiguration.java
URL: http://svn.apache.org/viewvc/uima/uima-ducc/trunk/uima-ducc-pullservice/src/main/java/org/apache/uima/ducc/ps/service/ServiceConfiguration.java?rev=1849499&r1=1849498&r2=1849499&view=diff
==============================================================================
--- uima/uima-ducc/trunk/uima-ducc-pullservice/src/main/java/org/apache/uima/ducc/ps/service/ServiceConfiguration.java (original)
+++ uima/uima-ducc/trunk/uima-ducc-pullservice/src/main/java/org/apache/uima/ducc/ps/service/ServiceConfiguration.java Fri Dec 21 22:00:22 2018
@@ -6,9 +6,9 @@
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
@@ -20,7 +20,6 @@
package org.apache.uima.ducc.ps.service;
import org.apache.uima.ducc.ps.service.errors.ServiceInitializationException;
-import org.apache.uima.ducc.ps.service.jmx.JMXAgent;
public class ServiceConfiguration {
private String clientURL;
@@ -49,7 +48,7 @@ public class ServiceConfiguration {
private int waitTimeWhenNoTaskGiven = 0;
private ClassLoader sysCL=null;
private String processType;
-
+
public String getProcessType() {
return processType;
}
@@ -213,7 +212,7 @@ public class ServiceConfiguration {
public void setServiceType(String serviceType) {
this.serviceType = serviceType;
}
-
+
// public String getAssignedJmxPort() {
// return assignedJmxPort;
// }
Modified: uima/uima-ducc/trunk/uima-ducc-pullservice/src/main/java/org/apache/uima/ducc/ps/service/dgen/DeployableGenerator.java
URL: http://svn.apache.org/viewvc/uima/uima-ducc/trunk/uima-ducc-pullservice/src/main/java/org/apache/uima/ducc/ps/service/dgen/DeployableGenerator.java?rev=1849499&r1=1849498&r2=1849499&view=diff
==============================================================================
--- uima/uima-ducc/trunk/uima-ducc-pullservice/src/main/java/org/apache/uima/ducc/ps/service/dgen/DeployableGenerator.java (original)
+++ uima/uima-ducc/trunk/uima-ducc-pullservice/src/main/java/org/apache/uima/ducc/ps/service/dgen/DeployableGenerator.java Fri Dec 21 22:00:22 2018
@@ -6,9 +6,9 @@
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
@@ -25,8 +25,6 @@ import java.io.File;
import java.io.FileOutputStream;
import java.io.FileWriter;
import java.io.StringWriter;
-import java.lang.reflect.InvocationTargetException;
-import java.lang.reflect.Method;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.StandardCopyOption;
@@ -61,15 +59,15 @@ public class DeployableGenerator {
private String userLogDir = null;
private Document doc;
private String registryURL;
-
+
public DeployableGenerator(String userLogDir) {
setUserLogDir(userLogDir);
}
-
+
private void setUserLogDir(String value) {
userLogDir = value;
}
-
+
public String generateAe(IDuccGeneratorUimaAggregate aggregateConfiguration, String jobId, boolean createUniqueFilename) throws Exception {
List<String> descriptorPaths = new ArrayList<String>();
List<List<String>> overrides = new ArrayList<List<String>>();
@@ -79,10 +77,10 @@ public class DeployableGenerator {
}
String aed = createAED(
aggregateConfiguration.getFlowController(),
- aggregateConfiguration.getThreadCount(),
+ aggregateConfiguration.getThreadCount(),
userLogDir,
createUniqueFilename ? null : jobId+"-"+"uima-ae-descriptor"+".xml",
- overrides,
+ overrides,
descriptorPaths.toArray(new String[descriptorPaths.size()])
);
return aed;
@@ -90,12 +88,12 @@ public class DeployableGenerator {
private static String createAED (
String flowController,
- int scaleup,
- String directory,
- String fname,
+ int scaleup,
+ String directory,
+ String fname,
List<List<String>> overrides,
String... aeDescriptors) throws Exception {
-
+
AnalysisEngineDescription aed = UimaUtils.createAggregateDescription(flowController, (scaleup > 1), overrides, aeDescriptors);
aed.getMetaData().setName("DUCC.job");
File dir = new File(directory);
@@ -116,10 +114,10 @@ public class DeployableGenerator {
Path target = source.resolveSibling(fname);
Files.move(source, target, StandardCopyOption.ATOMIC_MOVE);
return target.toString();
- }
+ }
catch(Exception e) {
throw e;
- }
+ }
finally {
if( fos != null ) {
fos.close();
@@ -130,14 +128,14 @@ public class DeployableGenerator {
try {
documentBuilderFactory.setFeature(DISALLOW_DOCTYPE_DECL, true);
} catch (ParserConfigurationException e1) {
- UIMAFramework.getLogger().log(Level.WARNING,
+ UIMAFramework.getLogger().log(Level.WARNING,
"DocumentBuilderFactory didn't recognize setting feature " + DISALLOW_DOCTYPE_DECL);
}
try {
documentBuilderFactory.setFeature(LOAD_EXTERNAL_DTD, false);
} catch (ParserConfigurationException e) {
- UIMAFramework.getLogger().log(Level.WARNING,
+ UIMAFramework.getLogger().log(Level.WARNING,
"DocumentBuilderFactory doesn't support feature " + LOAD_EXTERNAL_DTD);
}
@@ -147,22 +145,22 @@ public class DeployableGenerator {
/*
* This method is used by the JD to convert a deployment descriptor's inputQueue element
* to make it suitable for the JP's internal broker.
- * It is also used by the JP code since when running as a "pull" service it will be given an unconverted DD
+ * It is also used by the JP code since when running as a "pull" service it will be given an unconverted DD
*/
public String generateDd(IDuccGeneratorUimaReferenceByName configuration, String jobId, Boolean createUniqueFilename) throws Exception {
// Create DOM from the DD ... file or class-like name
String location = configuration.getReferenceByName();
org.apache.uima.util.XMLInputSource xmlin = UimaUtils.getXMLInputSource(location); // Reads from FS or classpath
-
+
DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
secureDocumentBuilderFactory(dbFactory);
DocumentBuilder db = dbFactory.newDocumentBuilder();
-
+
doc = db.parse(xmlin.getInputStream());
-
+
// Create converted descriptor if input is not a file or if endpoint or broker wrong
boolean createDescriptor = ! location.endsWith(".xml");
-
+
// locate the <inputQueue node within the xml ... should be only one
NodeList nodes = doc.getElementsByTagName("inputQueue");
Element element;
@@ -186,12 +184,12 @@ public class DeployableGenerator {
throw new Exception("Invalid DD-" + configuration.getReferenceByName()
+ ". Missing required element <inputQueue ...");
}
-
+
// Return the original descriptor or the converted one if necessary
return createDescriptor ? writeDDFile(xml2String(doc), jobId, createUniqueFilename) : location;
}
- /*
+ /*
* Deduce the scaleout for a deployment descriptor.
* If a top-level non-AS deployment check for a scaleout setting.
* Otherwise use the caspool size, with a default of 1
@@ -210,7 +208,7 @@ public class DeployableGenerator {
if (async.isEmpty()) {
if (aeElement.getElementsByTagName("delegates").getLength() == 0) {
async = "false";
- }
+ }
}
// If async is false a scaleout setting can override the caspool size
if (async.equals("false")) {
@@ -221,7 +219,7 @@ public class DeployableGenerator {
}
}
}
-
+
if (soValue.isEmpty()) {
nodes = doc.getElementsByTagName("casPool");
if (nodes.getLength() > 0) {
@@ -229,10 +227,10 @@ public class DeployableGenerator {
soValue = cpElement.getAttribute("numberOfCASes");
}
}
-
+
return soValue.isEmpty() ? 1 : Integer.parseInt(soValue);
}
-
+
public String getRegistryUrl() {
return registryURL;
}
@@ -240,27 +238,27 @@ public class DeployableGenerator {
try {
transformerFactory.setAttribute(ACCESS_EXTERNAL_DTD, "");
} catch (IllegalArgumentException e) {
- UIMAFramework.getLogger().log(Level.WARNING,
+ UIMAFramework.getLogger().log(Level.WARNING,
"TransformerFactory didn't recognize setting attribute " + ACCESS_EXTERNAL_DTD);
}
-
+
try {
transformerFactory.setAttribute(ACCESS_EXTERNAL_STYLESHEET, "");
} catch (IllegalArgumentException e) {
- UIMAFramework.getLogger().log(Level.WARNING,
+ UIMAFramework.getLogger().log(Level.WARNING,
"TransformerFactory didn't recognize setting attribute " + ACCESS_EXTERNAL_STYLESHEET);
}
}
private String xml2String(Document xmlDoc) throws Exception {
StringWriter writer = null;
-
+
DOMSource domSource = new DOMSource(xmlDoc.getDocumentElement());
-
+
writer = new StringWriter();
StreamResult streamResult = new StreamResult(writer);
-
+
TransformerFactory factory = TransformerFactory.newInstance();
secureTransformerFactory(factory);
@@ -270,7 +268,7 @@ public class DeployableGenerator {
StringBuffer serializedDD = writer.getBuffer();
return serializedDD.toString();
}
-
+
private String writeDDFile(String content, String jobId, boolean createUniqueFilename) throws Exception {
File dir = new File(userLogDir);
if ( !dir.exists()) {
@@ -299,7 +297,7 @@ public class DeployableGenerator {
}
}
}
-
+
// Don't delete descriptors if this environment variable is set
// (Can't put the key in IDuccUser as that is in the common project)
private static void deleteOnExitCheck(File f) {
Modified: uima/uima-ducc/trunk/uima-ducc-pullservice/src/main/java/org/apache/uima/ducc/ps/service/main/PullService.java
URL: http://svn.apache.org/viewvc/uima/uima-ducc/trunk/uima-ducc-pullservice/src/main/java/org/apache/uima/ducc/ps/service/main/PullService.java?rev=1849499&r1=1849498&r2=1849499&view=diff
==============================================================================
--- uima/uima-ducc/trunk/uima-ducc-pullservice/src/main/java/org/apache/uima/ducc/ps/service/main/PullService.java (original)
+++ uima/uima-ducc/trunk/uima-ducc-pullservice/src/main/java/org/apache/uima/ducc/ps/service/main/PullService.java Fri Dec 21 22:00:22 2018
@@ -34,7 +34,6 @@ import java.util.concurrent.locks.Reentr
import org.apache.uima.UIMAFramework;
import org.apache.uima.ducc.ps.ServiceThreadFactory;
import org.apache.uima.ducc.ps.service.IService;
-import org.apache.uima.ducc.ps.service.builders.PullServiceStepBuilder.OptionalsStep;
//import org.apache.uima.ducc.ps.service.ServiceConfiguration;
import org.apache.uima.ducc.ps.service.errors.IServiceErrorHandler;
import org.apache.uima.ducc.ps.service.errors.ServiceException;
@@ -44,7 +43,6 @@ import org.apache.uima.ducc.ps.service.p
import org.apache.uima.ducc.ps.service.protocol.IServiceProtocolHandler;
import org.apache.uima.ducc.ps.service.protocol.builtin.DefaultNoTaskAvailableStrategy;
import org.apache.uima.ducc.ps.service.protocol.builtin.DefaultServiceProtocolHandler;
-import org.apache.uima.ducc.ps.service.protocol.builtin.NoWaitStrategy;
import org.apache.uima.ducc.ps.service.registry.DefaultRegistryClient;
import org.apache.uima.ducc.ps.service.registry.IRegistryClient;
import org.apache.uima.ducc.ps.service.transport.IServiceTransport;
@@ -62,8 +60,8 @@ public class PullService implements ISer
// how many processing threads
private int scaleout=1;
// amount of time to wait when client has no tasks to give
- private int waitTimeInMillis=0;
-
+ private int waitTimeInMillis=0;
+
// application assigned service label
private String type;
private volatile boolean initialized = false;
@@ -95,8 +93,8 @@ public class PullService implements ISer
private Lock initLock = new ReentrantLock();
private Application application=null;
-
-
+
+
public PullService(String type) {
this(type,null);
@@ -107,7 +105,7 @@ public class PullService implements ISer
this.application = application;
}
-
+
public String getType() {
return type;
}
@@ -260,7 +258,7 @@ public class PullService implements ISer
// thread has been interrupted, force executor shutdown
threadPool.shutdownNow();
}
- }
+ }
}
@Override
@@ -282,7 +280,7 @@ public class PullService implements ISer
System.out.println(">>>>>>>> "+Utils.getTimestamp()+" "+Utils.getShortClassname(this.getClass())+" .dtop()-monitor stopped");
}
public void quiesceAndStop() {
- // when quiescing, let the process threads finish processing
+ // when quiescing, let the process threads finish processing
stopProtocolHandler(true); // true = quiesce
System.out.println(">>>>>>>> "+Utils.getTimestamp()+" "+Utils.getShortClassname(this.getClass())+" .quiesceAndStop()-protocol handler stopped");
// close connection to remote client and cleanup
@@ -307,7 +305,7 @@ public class PullService implements ISer
}
}
-
+
private void initializeTransport() throws ServiceInitializationException {
try {
transport.initialize();
@@ -333,7 +331,7 @@ public class PullService implements ISer
try {
logger.log(Level.INFO, "Stopping Process Thread Pool");
threadPool.shutdownNow();
-
+
// below probably not needed since this is done in start()
threadPool.awaitTermination(Long.MAX_VALUE, TimeUnit.MILLISECONDS);
logger.log(Level.INFO, "Process Thread Pool Stopped");
Modified: uima/uima-ducc/trunk/uima-ducc-pullservice/src/main/java/org/apache/uima/ducc/ps/service/main/ServiceWrapper.java
URL: http://svn.apache.org/viewvc/uima/uima-ducc/trunk/uima-ducc-pullservice/src/main/java/org/apache/uima/ducc/ps/service/main/ServiceWrapper.java?rev=1849499&r1=1849498&r2=1849499&view=diff
==============================================================================
--- uima/uima-ducc/trunk/uima-ducc-pullservice/src/main/java/org/apache/uima/ducc/ps/service/main/ServiceWrapper.java (original)
+++ uima/uima-ducc/trunk/uima-ducc-pullservice/src/main/java/org/apache/uima/ducc/ps/service/main/ServiceWrapper.java Fri Dec 21 22:00:22 2018
@@ -6,9 +6,9 @@
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
@@ -31,7 +31,6 @@ import org.apache.uima.ducc.ps.service.d
import org.apache.uima.ducc.ps.service.errors.IServiceErrorHandler;
import org.apache.uima.ducc.ps.service.errors.ServiceException;
import org.apache.uima.ducc.ps.service.errors.ServiceInitializationException;
-import org.apache.uima.ducc.ps.service.errors.IServiceErrorHandler.Action;
import org.apache.uima.ducc.ps.service.errors.builtin.WindowBasedErrorHandler;
import org.apache.uima.ducc.ps.service.jmx.JMXAgent;
import org.apache.uima.ducc.ps.service.processor.IServiceProcessor;
@@ -58,7 +57,7 @@ public class ServiceWrapper implements A
jmxAgent = new JMXAgent(serviceConfiguration.getServiceJmxConnectURL(), logger);
int rmiRegistryPort = jmxAgent.initialize();
return jmxAgent.start(rmiRegistryPort);
-
+
}
/**
@@ -67,12 +66,12 @@ public class ServiceWrapper implements A
* UimaServiceProcessor and for 'uima-as' it returns UimaAsServiceProcessor. If none of
* the above is specified and -Dducc.deploy.custom.processor.class=XX is defined, the code
* instatiates user provided ServiceProcessor.
- *
+ *
* @param analysisEngineDescriptorPath path to the AE descriptor
* @return IServiceProcessor instance
* @throws ServiceInitializationException
*/
- private IServiceProcessor createProcessor(String analysisEngineDescriptorPath, String[] args)
+ private IServiceProcessor createProcessor(String analysisEngineDescriptorPath, String[] args)
throws ServiceInitializationException{
IServiceProcessor serviceProcessor=null;
if ( serviceConfiguration.getCustomProcessorClass() != null ) {
@@ -100,34 +99,34 @@ public class ServiceWrapper implements A
} else {
if ( "uima".equals(serviceConfiguration.getJpType() ) ) {
serviceProcessor = new UimaServiceProcessor(analysisEngineDescriptorPath, serviceConfiguration);
-
+
} else if ( "uima-as".equals(serviceConfiguration.getJpType()) ) {
serviceProcessor = new UimaAsServiceProcessor(args, serviceConfiguration);
-
+
} else {
throw new RuntimeException("Invalid deployment. Set either -Dducc.deploy.JpType=[uima,uima-as] or provide -Dducc.deploy.custom.processor.class=XX where XX implements IServiceProcessor ");
}
- }
+ }
return serviceProcessor;
}
private IServiceErrorHandler getErrorHandler() {
int maxErrors = 1;
int windowSize = 1;
-
+
if ( serviceConfiguration.getMaxErrors() != null ) {
maxErrors = Integer.parseInt(serviceConfiguration.getMaxErrors());
}
if ( serviceConfiguration.getErrorWindowSize() != null ) {
windowSize = Integer.parseInt(serviceConfiguration.getErrorWindowSize());
}
- // Error handler which terminates service on the 1st error
+ // Error handler which terminates service on the 1st error
return new WindowBasedErrorHandler()
.withMaxFrameworkErrors(maxErrors)
.withProcessErrorWindow(windowSize).build();
}
/**
* Check if AE descriptor is provided or we need to create it from parts
- *
+ *
* @param serviceConfiguration
* @return
*/
@@ -140,7 +139,7 @@ public class ServiceWrapper implements A
serviceConfiguration.validateProperties();
addShutdownHook();
// validateProperties() call above checked if a user provided AE descriptor path
- String analysisEngineDescriptorPath;
+ String analysisEngineDescriptorPath;
// create JMX agent
String serviceJmxConnectString = startJmxAgent();
@@ -164,7 +163,7 @@ public class ServiceWrapper implements A
processor = createProcessor(analysisEngineDescriptorPath, args);
Objects.requireNonNull(processor, "Unable to instantiate IServiceProcessor");
-
+
if ( serviceConfiguration.getCustomRegistryClass() != null ) {
service = PullServiceStepBuilder.newBuilder(this)
.withProcessor(processor)
@@ -184,7 +183,7 @@ public class ServiceWrapper implements A
.withOptionalsDone().build();
}
-
+
service.initialize();
@@ -202,11 +201,11 @@ public class ServiceWrapper implements A
Constructor<?> ctor = clz.getConstructor(String.class);
registryClient = (IRegistryClient) ctor.newInstance(serviceConfiguration.getClientURL());
} catch(NoSuchMethodException ee) {
- // zero arg constructor. User must initialize this registry via custom -D's or environment
+ // zero arg constructor. User must initialize this registry via custom -D's or environment
registryClient = (IRegistryClient) clz.newInstance();
}
-
-
+
+
} catch( Exception e) {
logger.log(Level.WARNING,"",e);
throw new ServiceInitializationException("Unable to instantiate Custom Registry Client from class:"+serviceConfiguration.getCustomRegistryClass());
@@ -223,7 +222,7 @@ public class ServiceWrapper implements A
jmxAgent.stop();
}
} catch( Exception e) {
-
+
}
}
public void stop() {
@@ -235,7 +234,7 @@ public class ServiceWrapper implements A
logger.log(Level.WARNING,"",e);
}
-
+
}
public void quiesceAndStop() {
try {
@@ -248,7 +247,7 @@ public class ServiceWrapper implements A
logger.log(Level.WARNING,"",e);
}
-
+
}
public static void main(String[] args) {
ServiceWrapper wrapper = null;
@@ -267,7 +266,7 @@ public class ServiceWrapper implements A
static class ServiceShutdownHook extends Thread {
private ServiceWrapper serviceWrapper;
private Logger logger;
-
+
public ServiceShutdownHook(ServiceWrapper serviceWrapper, Logger logger ) {
this.serviceWrapper = serviceWrapper;
this.logger = logger;
@@ -276,8 +275,8 @@ public class ServiceWrapper implements A
public void run() {
try {
// Use System.out here since the logger may have already closed
- // its streams. Logger's shutdown hook could have run by now.
- System.out.println("Pull Service Caught SIGTERM Signal - Stopping (Quiescing) ...");
+ // its streams. Logger's shutdown hook could have run by now.
+ System.out.println("Pull Service Caught SIGTERM Signal - Stopping (Quiescing) ...");
//logger.log(Level.INFO, "Pull Service Caught SIGTERM Signal - Stopping (Quiescing) ...");
serviceWrapper.quiesceAndStop();
@@ -289,7 +288,7 @@ public class ServiceWrapper implements A
@Override
public void onServiceStop() {
stopJmx();
-
+
}
}