Author: challngr
Date: Thu Feb 21 16:06:37 2013
New Revision: 1448701

URL: http://svn.apache.org/r1448701
Log:
UIMA-2594
Save meta an svc properties for "implicit" service.  Must save it, 
update/resave, and
then clean up when the pinger is stopped for such a service.

Modified:
    
uima/sandbox/uima-ducc/trunk/uima-ducc-sm/src/main/java/org/apache/uima/ducc/sm/IServiceManager.java
    
uima/sandbox/uima-ducc/trunk/uima-ducc-sm/src/main/java/org/apache/uima/ducc/sm/ServiceHandler.java
    
uima/sandbox/uima-ducc/trunk/uima-ducc-sm/src/main/java/org/apache/uima/ducc/sm/ServiceManagerComponent.java
    
uima/sandbox/uima-ducc/trunk/uima-ducc-sm/src/main/java/org/apache/uima/ducc/sm/ServiceSet.java

Modified: 
uima/sandbox/uima-ducc/trunk/uima-ducc-sm/src/main/java/org/apache/uima/ducc/sm/IServiceManager.java
URL: 
http://svn.apache.org/viewvc/uima/sandbox/uima-ducc/trunk/uima-ducc-sm/src/main/java/org/apache/uima/ducc/sm/IServiceManager.java?rev=1448701&r1=1448700&r2=1448701&view=diff
==============================================================================
--- 
uima/sandbox/uima-ducc/trunk/uima-ducc-sm/src/main/java/org/apache/uima/ducc/sm/IServiceManager.java
 (original)
+++ 
uima/sandbox/uima-ducc/trunk/uima-ducc-sm/src/main/java/org/apache/uima/ducc/sm/IServiceManager.java
 Thu Feb 21 16:06:37 2013
@@ -18,6 +18,7 @@
 */
 package org.apache.uima.ducc.sm;
 
+import org.apache.uima.ducc.common.utils.id.DuccId;
 import org.apache.uima.ducc.transport.event.ServiceModifyEvent;
 import org.apache.uima.ducc.transport.event.ServiceQueryEvent;
 import org.apache.uima.ducc.transport.event.ServiceRegisterEvent;
@@ -54,4 +55,5 @@ public interface IServiceManager 
 
     public void publish(ServiceMap map);
 
+    public DuccId newId() throws Exception;
 }

Modified: 
uima/sandbox/uima-ducc/trunk/uima-ducc-sm/src/main/java/org/apache/uima/ducc/sm/ServiceHandler.java
URL: 
http://svn.apache.org/viewvc/uima/sandbox/uima-ducc/trunk/uima-ducc-sm/src/main/java/org/apache/uima/ducc/sm/ServiceHandler.java?rev=1448701&r1=1448700&r2=1448701&view=diff
==============================================================================
--- 
uima/sandbox/uima-ducc/trunk/uima-ducc-sm/src/main/java/org/apache/uima/ducc/sm/ServiceHandler.java
 (original)
+++ 
uima/sandbox/uima-ducc/trunk/uima-ducc-sm/src/main/java/org/apache/uima/ducc/sm/ServiceHandler.java
 Thu Feb 21 16:06:37 2013
@@ -19,7 +19,6 @@
 package org.apache.uima.ducc.sm;
 
 import java.io.File;
-import java.io.FileOutputStream;
 import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.List;
@@ -244,9 +243,9 @@ public class ServiceHandler
             ServiceSet sset = serviceStateHandler.getServiceByName(dep);       
                     
             if ( sset == null ) {                              // first time, 
so it's by reference only
                 try {
-                    sset = new ServiceSet(dep);
+                    sset = new ServiceSet(dep, serviceManager.newId());
                     serviceStateHandler.putServiceByName(dep, sset);
-                } catch ( IllegalArgumentException e ) {       // if 'dep' is 
invalid we throw
+                } catch ( Exception e ) {       // if 'dep' is invalid, or we 
can't get a duccid,  we throw
                     s.addMessage(dep, e.getMessage());
                     s.setState(ServiceState.NotAvailable);
                     fatal = true;
@@ -893,7 +892,7 @@ public class ServiceHandler
 
         if (serviceStateHandler.getServiceByName(key) == null ) {
             try {
-                props.store(new FileOutputStream(props_filename), "Service 
descriptor.");
+                sset.saveServiceProperties();
             } catch ( Exception e ) {
                 error = ("Internal error; unable to store service descriptor. 
" + key);
                 logger.error(methodName, id, e);
@@ -902,7 +901,7 @@ public class ServiceHandler
             
             try {
                 if ( ! must_deregister ) {
-                    meta.store(new FileOutputStream(meta_filename), "Meta 
descriptor");
+                    sset.saveMetaProperties();
                 }
             } catch ( Exception e ) {
                 error = ("Internal error; unable to store service 
meta-descriptor. " + key);
@@ -1028,17 +1027,19 @@ public class ServiceHandler
             serviceStateHandler.removeService(epname, friendly);
         }
 
-        String metafn =  sset.getMetaFilename();
-        String propsfn = sset.getPropsFilename();
+        sset.deleteProperties();
 
-        if ( metafn != null ) {
-            File mf = new File(metafn);
-            mf.delete();
-        }
-        if ( propsfn != null ) {
-            File pf = new File(propsfn);
-            pf.delete();
-        }
+        // String metafn =  sset.getMetaFilename();
+        // String propsfn = sset.getPropsFilename();
+
+        // if ( metafn != null ) {
+        //     File mf = new File(metafn);
+        //     mf.delete();
+        // }
+        // if ( propsfn != null ) {
+        //     File pf = new File(propsfn);
+        //     pf.delete();
+        // }
 
     }
 

Modified: 
uima/sandbox/uima-ducc/trunk/uima-ducc-sm/src/main/java/org/apache/uima/ducc/sm/ServiceManagerComponent.java
URL: 
http://svn.apache.org/viewvc/uima/sandbox/uima-ducc/trunk/uima-ducc-sm/src/main/java/org/apache/uima/ducc/sm/ServiceManagerComponent.java?rev=1448701&r1=1448700&r2=1448701&view=diff
==============================================================================
--- 
uima/sandbox/uima-ducc/trunk/uima-ducc-sm/src/main/java/org/apache/uima/ducc/sm/ServiceManagerComponent.java
 (original)
+++ 
uima/sandbox/uima-ducc/trunk/uima-ducc-sm/src/main/java/org/apache/uima/ducc/sm/ServiceManagerComponent.java
 Thu Feb 21 16:06:37 2013
@@ -178,10 +178,16 @@ public class ServiceManagerComponent 
         sm_props = new DuccProperties();
         File sf = new File(state_file);
         int seq = 0;
+        FileInputStream fos;
         if ( sf.exists() ) {
-            sm_props.load(new FileInputStream(state_file));
-            String s = sm_props.getProperty(service_seqno);
-            seq = Integer.parseInt(s) + 1;
+            fos = new FileInputStream(state_file);
+            try {
+                sm_props.load(fos);
+                String s = sm_props.getProperty(service_seqno);
+                seq = Integer.parseInt(s) + 1;
+            } finally {
+                fos.close();
+            }
         } 
 
         idFactory = new DuccIdFactory(seq);
@@ -771,7 +777,7 @@ public class ServiceManagerComponent 
         //ev.setReply(ServiceCode.OK, "Service not implemented.", 
"no-endpoint", null);
     }
 
-    private synchronized DuccId newId()
+    public synchronized DuccId newId()
         throws Exception
     {
         DuccId id = idFactory.next();

Modified: 
uima/sandbox/uima-ducc/trunk/uima-ducc-sm/src/main/java/org/apache/uima/ducc/sm/ServiceSet.java
URL: 
http://svn.apache.org/viewvc/uima/sandbox/uima-ducc/trunk/uima-ducc-sm/src/main/java/org/apache/uima/ducc/sm/ServiceSet.java?rev=1448701&r1=1448700&r2=1448701&view=diff
==============================================================================
--- 
uima/sandbox/uima-ducc/trunk/uima-ducc-sm/src/main/java/org/apache/uima/ducc/sm/ServiceSet.java
 (original)
+++ 
uima/sandbox/uima-ducc/trunk/uima-ducc-sm/src/main/java/org/apache/uima/ducc/sm/ServiceSet.java
 Thu Feb 21 16:06:37 2013
@@ -19,6 +19,7 @@
 package org.apache.uima.ducc.sm;
 
 import java.io.BufferedReader;
+import java.io.File;
 import java.io.FileNotFoundException;
 import java.io.FileOutputStream;
 import java.io.IOException;
@@ -119,14 +120,17 @@ public class ServiceSet
     //
     // This is the constructor for an implicit service
     //
-    public ServiceSet(String key)
+    public ServiceSet(String key, DuccId id)
     {
         this.key = key;
+        this.id = id;
         parseEndpoint(key);
 
         this.service_type = ServiceType.UimaAs;
         this.service_class = ServiceClass.Implicit;
 
+        String state_dir = System.getProperty("DUCC_HOME") + "/state";
+
         // need job props and meta props so pinger works
         // job props: , service_ping_class, service_ping_classpath, 
working_directory, log_directory
         // meta props: endpoint, user
@@ -138,6 +142,8 @@ public class ServiceSet
         job_props.put("working_directory", System.getProperty("user.dir")); // 
whatever my current dir is
         job_props.put("log_directory", System.getProperty("user.dir") + 
"/../logs");
         job_props.put("service_ping_jvm_args", "-Xmx50M");
+        props_filename = state_dir + "/services/" + id.toString() + ".svc";
+        saveServiceProperties();
 
         meta_props = new DuccProperties();
         meta_props.put("user", System.getProperty("user.name"));
@@ -150,6 +156,8 @@ public class ServiceSet
         meta_props.put("service-alive",      "false");
         meta_props.put("service-healthy",    "false");
         meta_props.put("service-statistics", "N/A");
+        meta_filename = state_dir + "/services/" + id.toString() + ".meta";
+        saveMetaProperties();
     }
 
     //
@@ -271,6 +279,22 @@ public class ServiceSet
 
     }
 
+    void deleteProperties()
+    {
+        // note that we're NOT synchronized - be sure to call this in a 
context where that's ok
+        // we want to avoid synchronizing on file activity in case somethng 
hangs.  which probably
+        // hoses us anyway :(
+        if ( meta_filename != null ) {
+             File mf = new File(meta_filename);
+             mf.delete();
+         }
+
+         if ( props_filename != null ) {
+             File pf = new File(props_filename);
+             pf.delete();
+         }
+    }
+
     void setIncoming(ServiceSet sset)
     {
         predecessors.add(sset);
@@ -493,7 +517,7 @@ public class ServiceSet
         return instances;
     }
 
-    private void saveMetaProperties()
+    void saveMetaProperties()
     {
         String methodName = "saveMetaProperties";
         meta_props.put("stopped", ""+stopped);
@@ -512,13 +536,40 @@ public class ServiceSet
             }
         }
         
-        try {
-                       meta_props.store(new FileOutputStream(meta_filename), 
"Meta descriptor");
+        FileOutputStream fos = null;
+        try {            
+                       fos = new FileOutputStream(meta_filename);            
+                       meta_props.store(fos, "Meta descriptor");
                } catch (FileNotFoundException e) {
             logger.warn(methodName, id, "Cannot save meta properties, file 
does not exist.");
                } catch (IOException e) {
             logger.warn(methodName, id, "I/O Error saving meta properties:", 
e);
-               }
+               } finally {
+            try {
+                               if ( fos != null ) fos.close();
+                       } catch (IOException e) {
+                       }
+        }
+        return;
+    }
+
+    void saveServiceProperties()
+    {
+        String methodName = "saveServiceProperties";
+        FileOutputStream fos = null;
+        try {
+               fos = new FileOutputStream(props_filename);
+                       job_props.store(fos, "Service descriptor");
+               } catch (FileNotFoundException e) {
+            logger.warn(methodName, id, "Cannot save service properties, file 
does not exist.");
+               } catch (IOException e) {
+            logger.warn(methodName, id, "I/O Error saving service 
properties:", e);
+               } finally {
+            try {
+                               if ( fos != null ) fos.close();
+                       } catch (IOException e) {
+                       }
+        }
         return;
     }
 
@@ -917,7 +968,11 @@ public class ServiceSet
                                                         // main state machine, 
and maybe ping restarted.
             serviceMeta = null;
         }
-        saveMetaProperties();
+        if ( isImplicit() ) {
+            deleteProperties();
+        } else {
+            saveMetaProperties();
+        }
     }
 
     public synchronized void stopPingThread()
@@ -928,7 +983,11 @@ public class ServiceSet
             serviceMeta.stop();
             serviceMeta = null;
         }
-        saveMetaProperties();
+        if ( isImplicit() ) {
+            deleteProperties();
+        } else {
+            saveMetaProperties();
+        }
     }
 
     synchronized void setResponsive()


Reply via email to