You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@uima.apache.org by cw...@apache.org on 2013/01/02 20:49:56 UTC
svn commit: r1427978 [7/7] - in
/uima/sandbox/uima-ducc/trunk/uima-ducc-transport/src: main/ main/java/
main/java/org/ main/java/org/apache/ main/java/org/apache/uima/
main/java/org/apache/uima/ducc/ main/java/org/apache/uima/ducc/transport/
main/java/...
Added: uima/sandbox/uima-ducc/trunk/uima-ducc-transport/src/main/java/org/apache/uima/ducc/transport/event/rm/IRmJobState.java
URL: http://svn.apache.org/viewvc/uima/sandbox/uima-ducc/trunk/uima-ducc-transport/src/main/java/org/apache/uima/ducc/transport/event/rm/IRmJobState.java?rev=1427978&view=auto
==============================================================================
--- uima/sandbox/uima-ducc/trunk/uima-ducc-transport/src/main/java/org/apache/uima/ducc/transport/event/rm/IRmJobState.java (added)
+++ uima/sandbox/uima-ducc/trunk/uima-ducc-transport/src/main/java/org/apache/uima/ducc/transport/event/rm/IRmJobState.java Wed Jan 2 19:49:53 2013
@@ -0,0 +1,84 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * 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
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+*/
+package org.apache.uima.ducc.transport.event.rm;
+
+import java.io.Serializable;
+import java.util.Map;
+
+import org.apache.uima.ducc.common.utils.id.DuccId;
+import org.apache.uima.ducc.transport.event.common.IDuccTypes.DuccType;
+
+
+/**
+ * This interface describes the scheduling state for one job, reservation, or service request.
+ */
+public interface IRmJobState extends Serializable
+{
+ /**
+ * Returns the the unique id of the job, reservation, or service request as assigned during submit, and passed in from JM
+ */
+ public DuccId getId();
+ public DuccType getDuccType(); // for messages :(
+
+ /**
+ * key is the share id, unique, as assigned by the RM
+ * value is the resource aka share
+ *
+ * On each update, the shares may
+ * a) stay the same
+ * b) increase - new shares added
+ * c) decrease - some shares removed
+ * d) increase and decrease - some shares removed and some shares added
+ */
+ Map<DuccId, IResource> getResources(); // the shares assigned to the job, if any
+
+ /**
+ * The resource manager must not remove shares from its own records until the JM has
+ * confirmed they are gone because there is an arbitrary period of time between the RM
+ * deallocating them and the resource becoming physically available.
+ *
+ * This interface returns the set of resources for each job that must be deallocated. They
+ * remain in RM's records as in-use until a JM state update confirms they have been removed.
+ *
+ * Key is the id of a share..
+ * Value is the share information as an IResource.
+ */
+ Map<DuccId, IResource> getPendingRemovals();
+
+ /**
+ * The RM marks a resource as busy immediately upon allocating it, altough there is
+ * an arbitrary period of time before it becomes actually busy. For each job with
+ * expanded resources, this list spells out exactly which resources are to be added.
+ *
+ * Key is the id of a share.
+ * Value is the share information as an IResource.
+ */
+ Map<DuccId, IResource> getPendingAdditions();
+
+ /**
+ * If RM has to refuse to handle a job, this flag says that.
+ */
+ boolean isRefused();
+
+ /**
+ * If isRefused() is true, this string contains a message explaining why.
+ */
+ String getReason();
+}
+
Propchange: uima/sandbox/uima-ducc/trunk/uima-ducc-transport/src/main/java/org/apache/uima/ducc/transport/event/rm/IRmJobState.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: uima/sandbox/uima-ducc/trunk/uima-ducc-transport/src/main/java/org/apache/uima/ducc/transport/event/rm/IRmStateEvent.java
URL: http://svn.apache.org/viewvc/uima/sandbox/uima-ducc/trunk/uima-ducc-transport/src/main/java/org/apache/uima/ducc/transport/event/rm/IRmStateEvent.java?rev=1427978&view=auto
==============================================================================
--- uima/sandbox/uima-ducc/trunk/uima-ducc-transport/src/main/java/org/apache/uima/ducc/transport/event/rm/IRmStateEvent.java (added)
+++ uima/sandbox/uima-ducc/trunk/uima-ducc-transport/src/main/java/org/apache/uima/ducc/transport/event/rm/IRmStateEvent.java Wed Jan 2 19:49:53 2013
@@ -0,0 +1,44 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * 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
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+*/
+package org.apache.uima.ducc.transport.event.rm;
+
+import java.util.Map;
+
+import org.apache.uima.ducc.common.utils.id.DuccId;
+
+
+/**
+ * This interface defines one state event from teh resource manager. It is a list of the states of all
+ * known jobs, reservations, and service requests.
+ */
+public interface IRmStateEvent
+{
+
+ /**
+ * Returns a map of the RM's view of the world.
+ *
+ * Key is the job's duccid as received from JM
+ * Value is RmJobState, which is the set of shares currently assigned to the job.
+ *
+ */
+ Map<DuccId, IRmJobState> getJobState(); // all the jobs rm knows about
+
+}
+
+
Propchange: uima/sandbox/uima-ducc/trunk/uima-ducc-transport/src/main/java/org/apache/uima/ducc/transport/event/rm/IRmStateEvent.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: uima/sandbox/uima-ducc/trunk/uima-ducc-transport/src/main/java/org/apache/uima/ducc/transport/event/rm/Resource.java
URL: http://svn.apache.org/viewvc/uima/sandbox/uima-ducc/trunk/uima-ducc-transport/src/main/java/org/apache/uima/ducc/transport/event/rm/Resource.java?rev=1427978&view=auto
==============================================================================
--- uima/sandbox/uima-ducc/trunk/uima-ducc-transport/src/main/java/org/apache/uima/ducc/transport/event/rm/Resource.java (added)
+++ uima/sandbox/uima-ducc/trunk/uima-ducc-transport/src/main/java/org/apache/uima/ducc/transport/event/rm/Resource.java Wed Jan 2 19:49:53 2013
@@ -0,0 +1,73 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * 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
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+*/
+package org.apache.uima.ducc.transport.event.rm;
+
+import org.apache.uima.ducc.common.NodeIdentity;
+import org.apache.uima.ducc.common.utils.id.DuccId;
+
+public class Resource implements IResource {
+
+ private DuccId duccId; // DuccId of the share, assigned by RM
+ private NodeIdentity nodeId; // Node id, assigned by Agent
+ private boolean purged; // Purged, for node failure
+ private int qShares; // Number of quantum shares this resource occupies
+
+ // dissallow
+ @SuppressWarnings("unused")
+ private Resource()
+ {
+ }
+
+ public Resource(DuccId duccId, NodeIdentity nodeId, boolean purged, int qShares)
+ {
+ this.duccId = duccId;
+ this.nodeId = nodeId;
+ this.purged = purged;
+ this.qShares = qShares;
+ }
+
+ @Override
+ public DuccId getId()
+ {
+ return duccId;
+ }
+
+ @Override
+ public NodeIdentity getNodeId()
+ {
+ return nodeId;
+ }
+
+ @Override
+ public boolean isPurged()
+ {
+ return purged;
+ }
+
+ @Override
+ public int countShares()
+ {
+ return qShares;
+ }
+
+ public String toString()
+ {
+ return nodeId.getName() + "." + duccId.getFriendly() + ( purged ? "[P]" : "");
+ }
+}
Propchange: uima/sandbox/uima-ducc/trunk/uima-ducc-transport/src/main/java/org/apache/uima/ducc/transport/event/rm/Resource.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: uima/sandbox/uima-ducc/trunk/uima-ducc-transport/src/main/java/org/apache/uima/ducc/transport/event/rm/RmJobState.java
URL: http://svn.apache.org/viewvc/uima/sandbox/uima-ducc/trunk/uima-ducc-transport/src/main/java/org/apache/uima/ducc/transport/event/rm/RmJobState.java?rev=1427978&view=auto
==============================================================================
--- uima/sandbox/uima-ducc/trunk/uima-ducc-transport/src/main/java/org/apache/uima/ducc/transport/event/rm/RmJobState.java (added)
+++ uima/sandbox/uima-ducc/trunk/uima-ducc-transport/src/main/java/org/apache/uima/ducc/transport/event/rm/RmJobState.java Wed Jan 2 19:49:53 2013
@@ -0,0 +1,110 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * 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
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+*/
+package org.apache.uima.ducc.transport.event.rm;
+
+import java.util.Map;
+
+import org.apache.uima.ducc.common.utils.id.DuccId;
+import org.apache.uima.ducc.transport.event.common.IDuccTypes.DuccType;
+
+
+public class RmJobState implements IRmJobState {
+
+ private DuccId duccId; // this job's DuccId as assigned by OR
+ private DuccType ducc_type; // for messages :(
+
+ // for all maps:
+ // key: DuccId of a share, assigned by RM
+ // value: A share as allocated by RM
+ private Map<DuccId, IResource> resources; // currently allocated
+ private Map<DuccId, IResource> pendingRemovals; // pending removals, which have not yet been confirmed by OR
+ private Map<DuccId, IResource> pendingAdditions; // pending additions, which have not yet been confirmed by OR
+
+ boolean refused = false; // is the job refussed by scheduler?
+ String reason = "<none>"; // if so, here's why
+
+ // disallow this constructor
+ @SuppressWarnings("unused")
+ private RmJobState()
+ {
+ }
+
+ public RmJobState(DuccId duccId,
+ Map<DuccId, IResource> resources,
+ Map<DuccId, IResource> removals,
+ Map<DuccId, IResource> additions)
+ {
+ this.duccId = duccId;
+ this.resources = resources;
+ this.pendingRemovals = removals;
+ this.pendingAdditions = additions;
+ }
+
+ public RmJobState(DuccId duccId, String refusalReason)
+ {
+ this.duccId = duccId;
+ this.refused = true;
+ this.reason = refusalReason;
+ }
+
+ @Override
+ public DuccId getId()
+ {
+ return duccId;
+ }
+
+
+ @Override
+ public Map<DuccId, IResource> getResources()
+ {
+ return resources;
+ }
+
+ @Override
+ public Map<DuccId, IResource> getPendingRemovals()
+ {
+ return pendingRemovals;
+ }
+
+ @Override
+ public Map<DuccId, IResource> getPendingAdditions()
+ {
+ return pendingAdditions;
+ }
+
+ public boolean isRefused()
+ {
+ return refused;
+ }
+
+ public String getReason()
+ {
+ return reason;
+ }
+
+ public DuccType getDuccType()
+ {
+ return ducc_type;
+ }
+
+ public void setDuccType(DuccType dt)
+ {
+ this.ducc_type = dt;
+ }
+}
Propchange: uima/sandbox/uima-ducc/trunk/uima-ducc-transport/src/main/java/org/apache/uima/ducc/transport/event/rm/RmJobState.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: uima/sandbox/uima-ducc/trunk/uima-ducc-transport/src/main/java/org/apache/uima/ducc/transport/event/sm/IService.java
URL: http://svn.apache.org/viewvc/uima/sandbox/uima-ducc/trunk/uima-ducc-transport/src/main/java/org/apache/uima/ducc/transport/event/sm/IService.java?rev=1427978&view=auto
==============================================================================
--- uima/sandbox/uima-ducc/trunk/uima-ducc-transport/src/main/java/org/apache/uima/ducc/transport/event/sm/IService.java (added)
+++ uima/sandbox/uima-ducc/trunk/uima-ducc-transport/src/main/java/org/apache/uima/ducc/transport/event/sm/IService.java Wed Jan 2 19:49:53 2013
@@ -0,0 +1,218 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * 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
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+*/
+package org.apache.uima.ducc.transport.event.sm;
+
+/**
+ * Service related constants that are public.
+ *
+ * Important: Do not put any methods into this interface. It is a holder for constants only.
+ */
+public interface IService
+{
+ static final String NULL = "<none>";
+ public static enum ServiceCode
+ {
+ OK, // API: The requested action succeeded
+ NOTOK // API: the Requested action did not succeed.
+ };
+
+ //
+ // For boolean options, we want a trinary: true, false, unset
+ public enum Trinary
+ {
+ True { public boolean decode() { return true; }},
+ False { public boolean decode() { return false; }},
+ Unset { public boolean decode() { throw new IllegalStateException("decode() is illegal for Trinary."); }} // must check explicitly, not decode
+ ;
+
+ public abstract boolean decode();
+ public static Trinary encode(String value)
+ {
+ if ( value.equals("true") ) return True;
+ if ( value.equals("false") ) return False;
+ return Unset;
+ }
+ };
+
+ public enum ServiceVerb
+ {
+ //
+ // I want to expose these things to the API with the ugly upper-case notation but don't
+ // want that ugliness in the variables, so we have encode and decode routines to do the
+ // correct translation.
+ //
+ Register {
+ public String decode() { return "register"; }
+ public String description() { return "Register a service."; }
+ public String argname() { return "service-DD-specification."; }
+ },
+ Unregister {
+ public String decode() { return "unregister" ; }
+ public String description() { return "Unregister a service." ; }
+ public String argname() { return "service-id-or-endpoint" ; }
+ },
+ Start {
+ public String decode() { return "start"; }
+ public String description() { return "Start a registered service." ; }
+ public String argname() { return "service-id-or-endpoint" ; }
+ },
+ Stop {
+ public String decode() { return "stop"; }
+ public String description() { return "Stop a registered service." ; }
+ public String argname() { return "wervice-id-or-endpoint [--instances number-to-stop]" ; }
+ },
+ Modify {
+ public String decode() { return "modify"; }
+ public String description() { return "Modify meta properties for a registered service." ; }
+ public String argname() { return "modify-parameters" ; }
+ },
+ Query {
+ public String decode() { return "query"; }
+ public String description() { return "Query registered services." ; }
+ public String argname() { return "none" ; }
+ },
+ Help {
+ public String decode() { return "help"; }
+ public String description() { return "This help message." ; }
+ public String argname() { return "none" ; }
+ },
+ Debug {
+ public String decode() { return "debug"; }
+ public String description() { return "Debug cli" ; }
+ public String argname() { return "none" ; }
+ },
+ Unknown {
+ public String decode() { return "unknown"; }
+ public String description() { return "unknown" ; }
+ public String argname() { return "unknown" ; }
+ },
+ ;
+
+ public abstract String decode();
+ public abstract String description();
+ public abstract String argname();
+
+ public static ServiceVerb encode(String value)
+ {
+ if ( value.equals("register") ) return Register;
+ if ( value.equals("unregister") ) return Unregister;
+ if ( value.equals("start") ) return Start;
+ if ( value.equals("stop") ) return Stop;
+ if ( value.equals("modify") ) return Modify;
+ if ( value.equals("query") ) return Query;
+ if ( value.equals("help") ) return Help;
+ if ( value.equals("debug") ) return Debug;
+
+ return Unknown;
+ }
+
+ };
+
+ public enum ServiceType
+ {
+ //
+ // I want to expose these things to the API with the ugly upper-case notation but don't
+ // want that ugliness in the variables, so we have encode and decode routines to do the
+ // correct translation.
+ //
+ UimaAs { public String decode() { return "UIMA-AS"; } },
+ Custom { public String decode() { return "CUSTOM" ; } },
+ Undefined { public String decode() { return "UNDEFINED"; } },
+ ;
+
+ public abstract String decode();
+
+ public static ServiceType encode(String value)
+ {
+ if ( value.equals("UIMA-AS") ) return UimaAs;
+ if ( value.equals("CUSTOM") ) return Custom;
+ return Undefined;
+ }
+ };
+
+ public enum ServiceClass
+ {
+ //
+ // I want to expose these things to the API with the ugly upper-case notation but don't
+ // want that ugliness in the variables, so we have encode and decode routines to do the
+ // correct translation.
+ //
+ Implicit { public String encode() { return "Implicit"; } },
+ Submitted { public String encode() { return "Submitted" ; } },
+ Registered { public String encode() { return "Registered"; } },
+ Custom { public String encode() { return "Custom"; } },
+ Undefined { public String encode() { return "Undefined"; } },
+ ;
+
+ public abstract String encode();
+
+ public static ServiceClass encode(String value)
+ {
+ if ( value.equals("Implicit" ) ) return Implicit;
+ if ( value.equals("Submitted" ) ) return Submitted;
+ if ( value.equals("Registered") ) return Registered;
+ if ( value.equals("Custom") ) return Custom;
+ return Undefined;
+ }
+ };
+
+ public enum ServiceState
+ {
+ //
+ // These things end up as strings in a props file where the custom is lower-case with - to separate words.
+ // In code we want to be able to use the nicer mixed-case names.
+ // Always use encode and decode and you can't get this wrong.
+ //
+ Waiting { public String decode() { return "waiting" ; } }, // A job is waiting on at least one service to ping
+ Initializing { public String decode() { return "initializing" ; } }, // A job is waiting on at least one service to initialize
+ Available { public String decode() { return "available" ; } }, // All services for this job are active and pinging, or else
+ // no services are needed for the job
+ NotAvailable { public String decode() { return "not-available" ; } }, // At least one service is not available and can't be made available
+ Stopping { public String decode() { return "stopping" ; } }, // Service is told to stop but it takes a while
+ Undefined { public String decode() { return "undefined" ; } }, // Catch-all, means basically "who cares"
+ ;
+
+ public abstract String decode();
+
+ public static ServiceState encode(String value)
+ {
+ if ( value.equals("waiting" ) ) return Waiting;
+ if ( value.equals("initializing" ) ) return Initializing;
+ if ( value.equals("available" ) ) return Available;
+ if ( value.equals("not-available" ) ) return NotAvailable;
+ if ( value.equals("stopping" ) ) return Stopping;
+ if ( value.equals("undefined" ) ) return Undefined;
+ return Undefined;
+ }
+
+ // used to accumulate multiple service states into a single value
+ public int ordinality()
+ {
+ switch ( this ) {
+ case Available: return 6;
+ case Initializing: return 5;
+ case Waiting: return 4;
+ case Stopping: return 3;
+ case NotAvailable: return 2;
+ case Undefined: return 1;
+ default: return 0;
+ }
+ }
+ };
+};
Propchange: uima/sandbox/uima-ducc/trunk/uima-ducc-transport/src/main/java/org/apache/uima/ducc/transport/event/sm/IService.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: uima/sandbox/uima-ducc/trunk/uima-ducc-transport/src/main/java/org/apache/uima/ducc/transport/event/sm/IServiceDescription.java
URL: http://svn.apache.org/viewvc/uima/sandbox/uima-ducc/trunk/uima-ducc-transport/src/main/java/org/apache/uima/ducc/transport/event/sm/IServiceDescription.java?rev=1427978&view=auto
==============================================================================
--- uima/sandbox/uima-ducc/trunk/uima-ducc-transport/src/main/java/org/apache/uima/ducc/transport/event/sm/IServiceDescription.java (added)
+++ uima/sandbox/uima-ducc/trunk/uima-ducc-transport/src/main/java/org/apache/uima/ducc/transport/event/sm/IServiceDescription.java Wed Jan 2 19:49:53 2013
@@ -0,0 +1,25 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * 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
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+*/
+package org.apache.uima.ducc.transport.event.sm;
+
+public interface IServiceDescription
+ extends IService
+{
+
+}
Propchange: uima/sandbox/uima-ducc/trunk/uima-ducc-transport/src/main/java/org/apache/uima/ducc/transport/event/sm/IServiceDescription.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: uima/sandbox/uima-ducc/trunk/uima-ducc-transport/src/main/java/org/apache/uima/ducc/transport/event/sm/ServiceDependency.java
URL: http://svn.apache.org/viewvc/uima/sandbox/uima-ducc/trunk/uima-ducc-transport/src/main/java/org/apache/uima/ducc/transport/event/sm/ServiceDependency.java?rev=1427978&view=auto
==============================================================================
--- uima/sandbox/uima-ducc/trunk/uima-ducc-transport/src/main/java/org/apache/uima/ducc/transport/event/sm/ServiceDependency.java (added)
+++ uima/sandbox/uima-ducc/trunk/uima-ducc-transport/src/main/java/org/apache/uima/ducc/transport/event/sm/ServiceDependency.java Wed Jan 2 19:49:53 2013
@@ -0,0 +1,74 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * 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
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+*/
+package org.apache.uima.ducc.transport.event.sm;
+
+import java.io.Serializable;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.uima.ducc.transport.event.sm.IService.ServiceState;
+
+
+@SuppressWarnings("serial")
+public class ServiceDependency implements Serializable {
+
+ private ServiceState state = ServiceState.Undefined; // this is the cumulative service state for all the job's services
+ private Map<String, String> messages = null; // if anything needs more info we put strings into here
+ // one per service, keyed on service endpoint
+
+ public ServiceDependency()
+ {
+ this.messages = new HashMap<String, String>();
+ }
+
+ /*
+ * Services State
+ */
+ public void setState(ServiceState state)
+ {
+ this.state = state;
+ }
+
+ public ServiceState getState()
+ {
+ return this.state;
+ }
+
+ /**
+ * Set service state. This is called at the end of resolving dependencies.
+ */
+ public void setIndividualState(String endpoint, ServiceState state)
+ {
+ messages.put(endpoint, state.decode());
+ }
+
+ /**
+ * Set an error message about the individual services.
+ */
+ public void addMessage(String endpoint, String message)
+ {
+ messages.put(endpoint, message);
+ }
+
+ public Map<String, String> getMessages()
+ {
+ return messages;
+ }
+
+}
Propchange: uima/sandbox/uima-ducc/trunk/uima-ducc-transport/src/main/java/org/apache/uima/ducc/transport/event/sm/ServiceDependency.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: uima/sandbox/uima-ducc/trunk/uima-ducc-transport/src/main/java/org/apache/uima/ducc/transport/event/sm/ServiceDescription.java
URL: http://svn.apache.org/viewvc/uima/sandbox/uima-ducc/trunk/uima-ducc-transport/src/main/java/org/apache/uima/ducc/transport/event/sm/ServiceDescription.java?rev=1427978&view=auto
==============================================================================
--- uima/sandbox/uima-ducc/trunk/uima-ducc-transport/src/main/java/org/apache/uima/ducc/transport/event/sm/ServiceDescription.java (added)
+++ uima/sandbox/uima-ducc/trunk/uima-ducc-transport/src/main/java/org/apache/uima/ducc/transport/event/sm/ServiceDescription.java Wed Jan 2 19:49:53 2013
@@ -0,0 +1,331 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * 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
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+*/
+package org.apache.uima.ducc.transport.event.sm;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.uima.ducc.common.ServiceStatistics;
+import org.apache.uima.ducc.common.utils.id.DuccId;
+import org.apache.uima.ducc.transport.event.common.IDuccState.JobState;
+
+
+
+public class ServiceDescription
+ implements IServiceDescription
+{
+ // For submitted and registered services
+ ArrayList<DuccId> implementors;
+
+ // key is job/service id, value is same. it's a map for fast existence check
+ ArrayList<DuccId> references;
+
+ // UIMA-AS or CUSTOM
+ ServiceType type;
+
+ // Implicit, Submitted, Registered
+ ServiceClass subclass;
+
+ // for uima-as
+ String endpoint;
+ String broker;
+
+ // The state we give OR - indicates availability of the service
+ ServiceState serviceState = ServiceState.Undefined;
+
+ // The state of the service as a DUCC job
+ JobState jobState;
+
+ // ping thread alive
+ boolean active;
+
+ // current autorstart state
+ boolean autostart = true;
+
+ // manual stop?
+ boolean stopped = false;
+
+ // for submitted service, the registered service id
+ DuccId id;
+ boolean deregistered; // still known but trying to shutdown
+
+ // number of registered instances
+ int instances;
+
+ long linger;
+ Map<String, String> dependencies;
+
+ ServiceStatistics qstats;
+
+ public DuccId getId() {
+ return id;
+ }
+
+ public void setId(DuccId id) {
+ this.id = id;
+ }
+
+ public ArrayList<DuccId> getImplementors() {
+ return implementors;
+ }
+
+ public void setImplementors(ArrayList<DuccId> implementors) {
+ this.implementors = implementors;
+ }
+
+ public ArrayList<DuccId> getReferences() {
+ return references;
+ }
+
+ public void setReferences(ArrayList<DuccId> references) {
+ this.references = references;
+ }
+
+ public ServiceType getType() {
+ return type;
+ }
+
+ public void setType(ServiceType type) {
+ this.type = type;
+ }
+
+ public ServiceClass getSubclass() {
+ return subclass;
+ }
+
+ public void setSubclass(ServiceClass subclass) {
+ this.subclass = subclass;
+ }
+
+ public String getEndpoint() {
+ return endpoint;
+ }
+
+ public void setEndpoint(String endpoint) {
+ this.endpoint = endpoint;
+ }
+
+ public String getBroker() {
+ return broker;
+ }
+
+ public void setBroker(String broker) {
+ this.broker = broker;
+ }
+
+ public ServiceState getServiceState() {
+ return serviceState;
+ }
+
+ public void setServiceState(ServiceState serviceState) {
+ this.serviceState = serviceState;
+ }
+
+ public JobState getJobState() {
+ return jobState;
+ }
+
+ public void setJobState(JobState jobState) {
+ this.jobState = jobState;
+ }
+
+ public boolean isActive() {
+ return active;
+ }
+
+ public void setActive(boolean active) {
+ this.active = active;
+ }
+
+ public void setDeregistered(boolean d)
+ {
+ this.deregistered = d;
+ }
+
+ public void setQueueStatistics(ServiceStatistics qstats)
+ {
+ this.qstats = qstats;
+ }
+
+ public ServiceStatistics getQueueStatistics()
+ {
+ return qstats;
+ }
+
+
+ public boolean isAutostart() {
+ return autostart;
+ }
+
+ public void setAutostart(boolean autostart) {
+ this.autostart = autostart;
+ }
+
+ public boolean isStopped() {
+ return stopped;
+ }
+
+ public void setStopped(boolean stopped) {
+ this.stopped = stopped;
+ }
+
+ public ServiceStatistics getQstats() {
+ return qstats;
+ }
+
+ public void setQstats(ServiceStatistics qstats) {
+ this.qstats = qstats;
+ }
+
+ public boolean isDeregistered() {
+ return deregistered;
+ }
+
+ public void setInstances(int instances)
+ {
+ this.instances = instances;
+ }
+
+ public int getInstances()
+ {
+ return instances;
+ }
+
+ public void setLinger(long linger)
+ {
+ this.linger = linger;
+ }
+
+ public long getLinger()
+ {
+ return this.linger;
+ }
+
+ public void addDependency(String endpoint, String msg)
+ {
+ if ( this.dependencies == null ) {
+ this.dependencies = new HashMap<String, String>();
+ }
+ this.dependencies.put(endpoint, msg);
+ }
+
+ public Map<String, String> getDependencies()
+ {
+ return this.dependencies;
+ }
+
+ public String toString()
+ {
+ StringBuffer sb = new StringBuffer();
+ sb.append("Service: ");
+ sb.append(type.decode());
+ sb.append(":");
+ sb.append(endpoint);
+
+ if ( type == ServiceType.UimaAs ) {
+ sb.append(":");
+ sb.append(broker);
+ }
+ sb.append("\n");
+
+ sb.append(" Service Class : ");
+ sb.append(subclass.encode());
+ switch ( subclass ) {
+ case Registered:
+ sb.append(" as ID ");
+ sb.append(id);
+ sb.append(" instances[");
+ sb.append(Integer.toString(instances));
+ sb.append("] linger[");
+ sb.append(Long.toString(linger));
+ sb.append("]");
+ break;
+ case Submitted:
+ case Implicit:
+ default:
+ }
+ sb.append("\n");
+
+ sb.append(" Implementors : ");
+ if ( implementors.size() > 0 ) {
+ for (DuccId id : implementors) {
+ sb.append(id);
+ sb.append(" ");
+ }
+ } else {
+ sb.append("(N/A)");
+ }
+ sb.append("\n");
+
+ sb.append(" References : ");
+ if ( references.size() > 0 ) {
+ for ( DuccId id : references ) {
+ sb.append(id);
+ sb.append(" ");
+ }
+ } else {
+ sb.append("None");
+ }
+ sb.append("\n");
+
+ sb.append(" Dependencies : ");
+ if ( dependencies == null ) {
+ sb.append("none\n");
+ } else {
+ sb.append("\n");
+ for ( String s : dependencies.keySet() ) {
+ sb.append(" ");
+ sb.append(s);
+ sb.append(": ");
+ sb.append(dependencies.get(s));
+ sb.append("\n");
+ }
+ }
+
+ sb.append(" Service State : ");
+ sb.append(serviceState);
+ sb.append("\n");
+
+ sb.append(" Ping Active : ");
+ sb.append(active);
+ sb.append("\n");
+
+ sb.append(" Autostart : ");
+ sb.append(autostart);
+ sb.append("\n");
+
+ sb.append(" Manual Stop : ");
+ sb.append(stopped);
+ sb.append("\n");
+
+ sb.append(" Queue Statistics: ");
+ if ( qstats == null ) {
+ sb.append("None\n");
+ } else {
+ sb.append("\n ");
+ sb.append(qstats.header());
+ sb.append("\n");
+ sb.append(" ");
+ sb.append(qstats.toString());
+ }
+ return sb.toString();
+ }
+
+}
Propchange: uima/sandbox/uima-ducc/trunk/uima-ducc-transport/src/main/java/org/apache/uima/ducc/transport/event/sm/ServiceDescription.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: uima/sandbox/uima-ducc/trunk/uima-ducc-transport/src/main/java/org/apache/uima/ducc/transport/event/sm/ServiceMap.java
URL: http://svn.apache.org/viewvc/uima/sandbox/uima-ducc/trunk/uima-ducc-transport/src/main/java/org/apache/uima/ducc/transport/event/sm/ServiceMap.java?rev=1427978&view=auto
==============================================================================
--- uima/sandbox/uima-ducc/trunk/uima-ducc-transport/src/main/java/org/apache/uima/ducc/transport/event/sm/ServiceMap.java (added)
+++ uima/sandbox/uima-ducc/trunk/uima-ducc-transport/src/main/java/org/apache/uima/ducc/transport/event/sm/ServiceMap.java Wed Jan 2 19:49:53 2013
@@ -0,0 +1,84 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * 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
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+*/
+package org.apache.uima.ducc.transport.event.sm;
+
+import java.io.Serializable;
+import java.util.Map;
+import java.util.Set;
+import java.util.concurrent.ConcurrentHashMap;
+
+import org.apache.uima.ducc.common.utils.id.DuccId;
+
+
+@SuppressWarnings("serial")
+
+// Note this is now a ConcurrentHahMap - most operations do not need to be synchronized.
+// Any method added here that loops should synchronize itself though, to insure
+// consistency over the operation.
+public class ServiceMap
+ extends ConcurrentHashMap<DuccId,ServiceDependency>
+ implements Serializable
+{
+ public void addService(DuccId duccId, ServiceDependency services)
+ {
+ super.put(duccId,services);
+ }
+
+
+ public void removeService(DuccId duccId)
+ {
+ super.remove(duccId);
+ }
+
+ public synchronized void removeAll(Set<DuccId> ids)
+ {
+ for ( Object o : ids ) {
+ super.remove(o);
+ }
+ }
+
+ public synchronized String toPrint()
+ {
+ StringBuffer sb = new StringBuffer("Service Map\n");
+ if ( size() == 0 ) {
+ sb.append("[empty]\n");
+ } else {
+ for ( DuccId id : keySet() ) {
+ ServiceDependency svc = get(id);
+ sb.append("Job ");
+ sb.append(id.toString());
+ sb.append(" Service state ");
+ sb.append(svc.getState().toString());
+
+ Map<String, String> msgs = svc.getMessages();
+ if (msgs != null ) {
+ for ( String s : msgs.keySet() ) {
+ sb.append(" [");
+ sb.append(s);
+ sb.append(" : ");
+ sb.append(msgs.get(s));
+ sb.append("] ");
+ }
+ }
+ sb.append("\n");
+ }
+ }
+ return sb.toString();
+ }
+}
Propchange: uima/sandbox/uima-ducc/trunk/uima-ducc-transport/src/main/java/org/apache/uima/ducc/transport/event/sm/ServiceMap.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: uima/sandbox/uima-ducc/trunk/uima-ducc-transport/src/main/java/org/apache/uima/ducc/transport/jms/JmsTransport.java
URL: http://svn.apache.org/viewvc/uima/sandbox/uima-ducc/trunk/uima-ducc-transport/src/main/java/org/apache/uima/ducc/transport/jms/JmsTransport.java?rev=1427978&view=auto
==============================================================================
--- uima/sandbox/uima-ducc/trunk/uima-ducc-transport/src/main/java/org/apache/uima/ducc/transport/jms/JmsTransport.java (added)
+++ uima/sandbox/uima-ducc/trunk/uima-ducc-transport/src/main/java/org/apache/uima/ducc/transport/jms/JmsTransport.java Wed Jan 2 19:49:53 2013
@@ -0,0 +1,85 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * 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
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+*/
+package org.apache.uima.ducc.transport.jms;
+
+import javax.jms.ConnectionFactory;
+
+import org.apache.activemq.ActiveMQConnectionFactory;
+import org.apache.camel.CamelContext;
+import org.apache.camel.component.jms.JmsComponent;
+import org.apache.uima.ducc.common.config.CommonConfiguration;
+import org.apache.uima.ducc.transport.dispatcher.DuccEventDispatcher;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.context.annotation.Import;
+
+
+
+@Configuration
+
+@Import({CommonConfiguration.class})
+public class JmsTransport {
+ @Autowired CommonConfiguration common;
+ //@Autowired CamelContext context;
+ @Value("#{ systemProperties['ducc.broker.url'] }")String brokerUrl;
+
+ @Bean
+ public CamelContext jmsContext() {
+ CamelContext ctx = common.camelContext();
+ if ( ctx.getComponent("activemq") == null ) {
+ ConnectionFactory connectionFactory =
+ new ActiveMQConnectionFactory(brokerUrl);
+ JmsComponent jmsComponent = JmsComponent.jmsComponentAutoAcknowledge(connectionFactory);
+// jmsComponent.setUseMessageIDAsCorrelationID(true);
+ // jmsComponent.setConcurrentConsumers(maxServerTasks);
+// common.camelContext().addComponent("activemq", jmsComponent);
+ ctx.addComponent("activemq", jmsComponent);
+ }
+
+// if ( context.getComponent("activemq") == null ) {
+// context.addComponent("activemq", ActiveMQComponent.activeMQComponent(brokerUrl));
+// }
+// return common.camelContext();
+ return ctx;
+ }
+ @Bean
+ public CamelContext jmsContextWithClientACK() {
+ CamelContext ctx = common.camelContext();
+ if ( ctx.getComponent("activemq") == null ) {
+ ConnectionFactory connectionFactory =
+ new ActiveMQConnectionFactory(brokerUrl);
+ JmsComponent jmsComponent = JmsComponent.jmsComponentClientAcknowledge(connectionFactory);
+// jmsComponent.setUseMessageIDAsCorrelationID(true);
+ // jmsComponent.setConcurrentConsumers(maxServerTasks);
+ ctx.addComponent("activemq", jmsComponent);
+ }
+
+// if ( context.getComponent("activemq") == null ) {
+// context.addComponent("activemq", ActiveMQComponent.activeMQComponent(brokerUrl));
+// }
+// return common.camelContext();
+ return ctx;
+ }
+ @Bean
+ public DuccEventDispatcher duccEventDispatcher() {
+ return new DuccEventDispatcher(common.camelContext());
+ }
+}
Propchange: uima/sandbox/uima-ducc/trunk/uima-ducc-transport/src/main/java/org/apache/uima/ducc/transport/jms/JmsTransport.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: uima/sandbox/uima-ducc/trunk/uima-ducc-transport/src/main/java/org/apache/uima/ducc/transport/seda/SedaTransport.java
URL: http://svn.apache.org/viewvc/uima/sandbox/uima-ducc/trunk/uima-ducc-transport/src/main/java/org/apache/uima/ducc/transport/seda/SedaTransport.java?rev=1427978&view=auto
==============================================================================
--- uima/sandbox/uima-ducc/trunk/uima-ducc-transport/src/main/java/org/apache/uima/ducc/transport/seda/SedaTransport.java (added)
+++ uima/sandbox/uima-ducc/trunk/uima-ducc-transport/src/main/java/org/apache/uima/ducc/transport/seda/SedaTransport.java Wed Jan 2 19:49:53 2013
@@ -0,0 +1,23 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * 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
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+*/
+package org.apache.uima.ducc.transport.seda;
+
+public class SedaTransport {
+
+}
Propchange: uima/sandbox/uima-ducc/trunk/uima-ducc-transport/src/main/java/org/apache/uima/ducc/transport/seda/SedaTransport.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: uima/sandbox/uima-ducc/trunk/uima-ducc-transport/src/main/java/org/apache/uima/ducc/transport/uima/dd/generator/DeploymentDescriptorGenerator.java
URL: http://svn.apache.org/viewvc/uima/sandbox/uima-ducc/trunk/uima-ducc-transport/src/main/java/org/apache/uima/ducc/transport/uima/dd/generator/DeploymentDescriptorGenerator.java?rev=1427978&view=auto
==============================================================================
--- uima/sandbox/uima-ducc/trunk/uima-ducc-transport/src/main/java/org/apache/uima/ducc/transport/uima/dd/generator/DeploymentDescriptorGenerator.java (added)
+++ uima/sandbox/uima-ducc/trunk/uima-ducc-transport/src/main/java/org/apache/uima/ducc/transport/uima/dd/generator/DeploymentDescriptorGenerator.java Wed Jan 2 19:49:53 2013
@@ -0,0 +1,265 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * 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
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+*/
+package org.apache.uima.ducc.transport.uima.dd.generator;
+
+import java.io.BufferedWriter;
+import java.io.File;
+import java.io.FileWriter;
+import java.io.StringWriter;
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.transform.Transformer;
+import javax.xml.transform.TransformerFactory;
+import javax.xml.transform.dom.DOMSource;
+import javax.xml.transform.stream.StreamResult;
+
+import org.apache.uima.ducc.common.uima.UimaUtils;
+import org.apache.uima.ducc.common.utils.DuccLogger;
+import org.apache.uima.ducc.common.utils.Utils;
+import org.apache.uima.ducc.common.utils.XStreamUtils;
+import org.apache.uima.ducc.transport.event.common.DuccUimaAggregate;
+import org.apache.uima.ducc.transport.event.common.DuccUimaAggregateComponent;
+import org.apache.uima.ducc.transport.event.common.DuccUimaDeploymentDescriptor;
+import org.apache.uima.ducc.transport.event.common.IDuccUimaAggregate;
+import org.apache.uima.ducc.transport.event.common.IDuccUimaAggregateComponent;
+import org.apache.uima.ducc.transport.event.common.IDuccUimaDeployableConfiguration;
+import org.apache.uima.ducc.transport.event.common.IDuccUimaDeploymentDescriptor;
+import org.apache.uima.resourceSpecifier.factory.UimaASPrimitiveDeploymentDescriptor;
+import org.apache.uima.util.XMLInputSource;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+import org.w3c.dom.NodeList;
+
+/**
+ * Generates UIMA AS deployment descriptor. Takes in as input implementations of
+ * IDuccUimaDeployableConfiguration interface creates a DD. Currently two implementations
+ * of IDuccUimaDeployableConfiguration are supported:
+ *
+ * 1) IDuccUimaDeploymentDescriptor - this contains a reference to an existing DD that a
+ * user provided when submitting a job. In this case, the code overrides a queue name
+ * and a broker url and new descriptors are generated.
+ *
+ * 2) IDuccUimaAggregate - this contains a list of delegate components that must first
+ * be assembled into UIMA Aggregate descriptor. After generating that descriptor the
+ * code generates DD for it.
+ */
+public class DeploymentDescriptorGenerator {
+
+ private DuccLogger logger; // logger to use
+ private String duccComponentName; // DUCC component using this class (JD)
+ private String userLogDir; // where to write both descriptors
+
+ public DeploymentDescriptorGenerator(String componentName, DuccLogger logger, String userLogDir) {
+ this.logger = logger;
+ // Type of ducc component this is using this class (ex.JD)
+ this.duccComponentName = componentName;
+ this.userLogDir = userLogDir;
+ }
+ public String generate(String serializedDeployableConfiguration, String jobId) throws Exception {
+ IDuccUimaDeployableConfiguration deployableConfiguration =
+ (IDuccUimaDeployableConfiguration)XStreamUtils.unmarshall(serializedDeployableConfiguration);
+ return generate(deployableConfiguration, jobId);
+ }
+
+ public String getComponentName() {
+ return duccComponentName;
+ }
+
+ /**
+ * Generates deployment descriptor for DUCC JPs.
+ *
+ * @param configuration - deployment configuration for the deployment descriptor
+ * @return - absolute path to the generated deployment descriptor
+ * @throws Exception - failure
+ */
+ public String generate(IDuccUimaDeployableConfiguration configuration, String jobId)
+ throws Exception {
+ String methodName="generate";
+ if ( configuration instanceof IDuccUimaDeploymentDescriptor) {
+ logger.debug(methodName, null, "DUCC Service Wrapper Generates Deployment Descriptor Based on DD Provided by a User:"+((IDuccUimaDeploymentDescriptor)configuration).getDeploymentDescriptorPath());
+ // User provided descriptor is used as a basis for generating the actual DD with overriden
+ // Broker URL and queue name.
+ return generateDeploymentDescriptor((IDuccUimaDeploymentDescriptor)configuration, jobId);
+ } else if ( configuration instanceof IDuccUimaAggregate) {
+ logger.debug(methodName, null,"DUCC Service Wrapper Generating UIMA AS Deployment Descriptor");
+ // First create UIMA aggregate descriptor and then a deployment descriptor.
+ return generateDeploymentDescriptor((IDuccUimaAggregate)configuration, jobId);
+ } else throw new Exception("Invalid IDuccUimaDeployableConfiguration. Expected IDuccUimaAggregate or IDuccUimaDeploymentDescriptor, but received "+configuration.getClass().getName());
+ }
+ /**
+ * Writes a given content into a file in a given directory
+ *
+ * @param content - content in the file
+ * @return - absolute path to the file created
+ *
+ * @throws Exception
+ */
+ private String writeDDFile(String content, String jobId) throws Exception {
+ File dir = new File(userLogDir);
+ if ( !dir.exists()) {
+ dir.mkdir();
+ }
+ // compose the file name from a basename (from ducc.properties), constant (-uima-as.dd-) and PID
+ BufferedWriter out = null;
+ try {
+ // using PID of the ducc component process in the DD file name
+ File file = new File(dir, jobId+"-uima-as-dd-"+Utils.getPID()+".xml");
+ out = new BufferedWriter(new FileWriter(file));
+ out.write(content);
+ out.flush();
+ return file.getAbsolutePath();
+ } catch( Exception e) {
+ throw e;
+ } finally {
+ if ( out != null ) {
+ out.close();
+ }
+ }
+ }
+ /**
+ * Modifies user provided deployment descriptor by changing queue name and broker URL and
+ * writes it to a new deployment descriptor file.
+ *
+ * @param dd - user specified deployment descriptor
+ * @return - absolute path to the generated deployment descriptor
+ * @throws Exception
+ */
+ public String generateDeploymentDescriptor(IDuccUimaDeploymentDescriptor dd, String jobId) throws Exception {
+ // parse DD into DOM
+ Document doc = parse(dd.getDeploymentDescriptorPath());
+ // locate the <inputQueue node within the xml
+ NodeList nodes = doc.getElementsByTagName("inputQueue");
+ // should only be one such node
+ if ( nodes.getLength() > 0 ) {
+ Element element = (Element) nodes.item(0);
+ // replace queue name
+ element.setAttribute("endpoint", "ducc.jd.queue."+jobId);
+ // replace broker URL
+ element.setAttribute("brokerURL", System.getProperty("ducc.broker.url"));
+ } else {
+ throw new Exception("Invalid DD-"+dd.getDeploymentDescriptorPath()+". Missing required element <inputQueue ...");
+ }
+ //
+ // write the adjusted deployment descriptor to the user log dir where dd2spring will
+ // pick it up from
+ //
+ return writeDDFile(xml2String(doc), jobId);
+ }
+ /**
+ * Parses xml into DOM
+ *
+ * @param location - name of the xml file to parse
+ * @return DOM
+ * @throws Exception
+ */
+ private Document parse(String location ) throws Exception {
+ // Resolve the descriptor either by name or by location
+ XMLInputSource xmlin =
+ UimaUtils.getXMLInputSource(location); // this guy does all the magic
+ // Parse the descriptor into DOM
+ DocumentBuilder db = DocumentBuilderFactory.newInstance().newDocumentBuilder();
+ return db.parse(xmlin.getInputStream());
+ }
+ /**
+ * Serializes Deployment Descriptor from DOM to a String
+ * @param xmlDoc - xml to serialize
+ * @return - serialized DD
+ * @throws Exception
+ */
+ 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();
+ Transformer transformer = factory.newTransformer();
+ transformer.transform(domSource, streamResult);
+
+ StringBuffer serializedDD = writer.getBuffer();
+ return serializedDD.toString();
+ }
+ /**
+ * Creates and returns absolute path to the UIMA AS deployment descriptor.
+ *
+ * @param aggregateConfiguration - configuration object containing UIMA aggregate delegate
+ * configuration and overrides.
+ *
+ * @return - absolute path to the generated deployment descriptor
+ * @throws Exception
+ */
+ private String generateDeploymentDescriptor(IDuccUimaAggregate aggregateConfiguration, String jobId ) throws Exception {
+
+ List<String> descriptorPaths = new ArrayList<String>();
+ List<List<String>> overrides = new ArrayList<List<String>>();
+ for( IDuccUimaAggregateComponent component: aggregateConfiguration.getComponents()) {
+ descriptorPaths.add(component.getDescriptor());
+ overrides.add(component.getOverrides());
+ }
+ UimaASPrimitiveDeploymentDescriptor dd =
+ UimaUtils.createUimaASDeploymentDescriptor(
+ aggregateConfiguration.getName(),
+ aggregateConfiguration.getDescription(),
+ aggregateConfiguration.getBrokerURL(),
+ aggregateConfiguration.getEndpoint(),
+ aggregateConfiguration.getThreadCount(),
+ userLogDir,
+ jobId+"-uima-ae-descriptor-"+Utils.getPID()+".xml",
+ overrides,
+ descriptorPaths.toArray(new String[descriptorPaths.size()])
+ );
+ return writeDDFile(dd.toXML(), jobId);
+ }
+ public static void main(String args[]) {
+ DuccLogger logger=null;
+ try {
+ logger = new DuccLogger(DeploymentDescriptorGenerator.class, "TestDuccComponent");
+ String logDir = System.getProperty("user.dir");
+ DeploymentDescriptorGenerator
+ ddg = new DeploymentDescriptorGenerator("JD", logger, logDir);
+
+
+ IDuccUimaDeploymentDescriptor dd = new DuccUimaDeploymentDescriptor(args[0]);
+ ddg.generateDeploymentDescriptor(dd,"120");
+
+
+
+
+
+ DuccUimaAggregate dua = new DuccUimaAggregate("TestAggregate", "Some Description", 1, "tcp://localhost:61616", "uima-as.jd.3");
+ DuccUimaAggregateComponent duac = new DuccUimaAggregateComponent("org.apache.uima.ducc.common.test.randomsleep.RandomSleepAE", new ArrayList<String>());
+ List<IDuccUimaAggregateComponent> components =
+ new ArrayList<IDuccUimaAggregateComponent>();
+ components.add(duac);
+ dua.setComponents(components);
+ String serializedDD = ddg.generate(dua,"3");
+ System.out.println(">>>>>>>>> DD Path:"+serializedDD);
+ } catch( Exception e) {
+ e.printStackTrace();
+ } finally {
+ if ( logger != null ) {
+ logger.shutdown();
+ }
+ }
+ }
+}
Propchange: uima/sandbox/uima-ducc/trunk/uima-ducc-transport/src/main/java/org/apache/uima/ducc/transport/uima/dd/generator/DeploymentDescriptorGenerator.java
------------------------------------------------------------------------------
svn:eol-style = native