]>
git.argeo.org Git - gpl/argeo-slc.git/blob - runtime/org.argeo.slc.support.jcr/src/main/java/org/argeo/slc/jcr/execution/JcrExecutionProcess.java
cca76d95ba57d98e8e36116c1bfb9bba04607893
2 * Copyright (C) 2007-2012 Mathieu Baudier
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
16 package org
.argeo
.slc
.jcr
.execution
;
18 import java
.util
.Calendar
;
19 import java
.util
.GregorianCalendar
;
20 import java
.util
.List
;
22 import javax
.jcr
.Node
;
23 import javax
.jcr
.RepositoryException
;
25 import org
.apache
.commons
.logging
.Log
;
26 import org
.apache
.commons
.logging
.LogFactory
;
27 import org
.argeo
.jcr
.JcrUtils
;
28 import org
.argeo
.slc
.SlcException
;
29 import org
.argeo
.slc
.execution
.ExecutionProcess
;
30 import org
.argeo
.slc
.execution
.ExecutionStep
;
31 import org
.argeo
.slc
.jcr
.SlcNames
;
32 import org
.argeo
.slc
.jcr
.SlcTypes
;
34 /** Execution process implementation based on a JCR node. */
35 public class JcrExecutionProcess
implements ExecutionProcess
, SlcNames
{
36 private Log log
= LogFactory
.getLog(JcrExecutionProcess
.class);
37 private final Node node
;
39 private Long nextLogLine
= 1l;
41 public JcrExecutionProcess(Node node
) {
45 public String
getUuid() {
47 return node
.getProperty(SLC_UUID
).getString();
48 } catch (RepositoryException e
) {
49 throw new SlcException("Cannot get uuid for " + node
, e
);
53 public String
getStatus() {
55 return node
.getProperty(SLC_STATUS
).getString();
56 } catch (RepositoryException e
) {
57 log
.error("Cannot get status: " + e
);
58 // we should re-throw exception because this information can
59 // probably used for monitoring in case there are already unexpected
65 public void setStatus(String status
) {
67 node
.setProperty(SLC_STATUS
, status
);
68 // last modified properties needs to be manually updated
69 // see https://issues.apache.org/jira/browse/JCR-2233
70 JcrUtils
.updateLastModified(node
);
71 node
.getSession().save();
72 } catch (RepositoryException e
) {
73 JcrUtils
.discardUnderlyingSessionQuietly(node
);
74 // we should re-throw exception because this information can
75 // probably used for monitoring in case there are already unexpected
77 log
.error("Cannot set status " + status
+ ": " + e
);
82 * Synchronized in order to make sure that there is no concurrent
83 * modification of {@link #nextLogLine}.
85 public synchronized void addSteps(List
<ExecutionStep
> steps
) {
87 steps
: for (ExecutionStep step
: steps
) {
89 if (step
.getType().equals(ExecutionStep
.TRACE
))
90 type
= SlcTypes
.SLC_LOG_TRACE
;
91 else if (step
.getType().equals(ExecutionStep
.DEBUG
))
92 type
= SlcTypes
.SLC_LOG_DEBUG
;
93 else if (step
.getType().equals(ExecutionStep
.INFO
))
94 type
= SlcTypes
.SLC_LOG_INFO
;
95 else if (step
.getType().equals(ExecutionStep
.WARNING
))
96 type
= SlcTypes
.SLC_LOG_WARNING
;
97 else if (step
.getType().equals(ExecutionStep
.ERROR
))
98 type
= SlcTypes
.SLC_LOG_ERROR
;
103 String relPath
= SLC_LOG
+ '/'
104 + step
.getThread().replace('/', '_') + '/'
105 + step
.getLocation().replace('.', '/');
106 String path
= node
.getPath() + '/' + relPath
;
107 // clean special character
108 // TODO factorize in JcrUtils
109 path
= path
.replace('@', '_').replace(':', '_');
111 Node location
= JcrUtils
.mkdirs(node
.getSession(), path
);
112 Node logEntry
= location
.addNode(Long
.toString(nextLogLine
),
114 logEntry
.setProperty(SLC_MESSAGE
, step
.getLog());
115 Calendar calendar
= new GregorianCalendar();
116 calendar
.setTime(step
.getTimestamp());
117 logEntry
.setProperty(SLC_TIMESTAMP
, calendar
);
119 // System.out.println("Logged " + logEntry.getPath());
124 // last modified properties needs to be manually updated
125 // see https://issues.apache.org/jira/browse/JCR-2233
126 JcrUtils
.updateLastModified(node
);
128 node
.getSession().save();
129 } catch (Exception e
) {
130 JcrUtils
.discardUnderlyingSessionQuietly(node
);
135 public Node
getNode() {