]> git.argeo.org Git - gpl/argeo-slc.git/blob - runtime/org.argeo.slc.core/src/main/java/org/argeo/slc/core/runtime/DefaultAgent.java
ca230856f4f2103f3288dfacf49cd52edb52d382
[gpl/argeo-slc.git] / runtime / org.argeo.slc.core / src / main / java / org / argeo / slc / core / runtime / DefaultAgent.java
1 /*
2 * Copyright (C) 2010 Mathieu Baudier <mbaudier@argeo.org>
3 *
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
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
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.
15 */
16
17 package org.argeo.slc.core.runtime;
18
19 import java.net.InetAddress;
20 import java.net.UnknownHostException;
21 import java.util.List;
22 import java.util.UUID;
23
24 import org.argeo.slc.SlcException;
25 import org.argeo.slc.execution.ExecutionModuleDescriptor;
26 import org.argeo.slc.execution.ExecutionModulesManager;
27 import org.argeo.slc.process.SlcExecution;
28 import org.argeo.slc.runtime.SlcAgent;
29 import org.argeo.slc.runtime.SlcAgentDescriptor;
30
31 /** Implements the base methods of an SLC agent. */
32 public class DefaultAgent implements SlcAgent {
33 private SlcAgentDescriptor agentDescriptor;
34 private ExecutionModulesManager modulesManager;
35
36 /*
37 * LIFECYCLE
38 */
39 public void init() {
40 try {
41 agentDescriptor = new SlcAgentDescriptor();
42 agentDescriptor.setUuid(initAgentUuid());
43 agentDescriptor.setHost(InetAddress.getLocalHost().getHostName());
44 } catch (UnknownHostException e) {
45 throw new SlcException("Unable to create agent descriptor.", e);
46 }
47 }
48
49 public void dispose() {
50
51 }
52
53 /**
54 * Called during initialization in order to determines the agent UUID. To be
55 * overridden. By default creates a new one per instance.
56 */
57 protected String initAgentUuid() {
58 return UUID.randomUUID().toString();
59 }
60
61 /*
62 * SLC AGENT
63 */
64 public void runSlcExecution(final SlcExecution slcExecution) {
65 modulesManager.process(slcExecution);
66 }
67
68 public ExecutionModuleDescriptor getExecutionModuleDescriptor(
69 String moduleName, String version) {
70 return modulesManager.getExecutionModuleDescriptor(moduleName, version);
71 }
72
73 public List<ExecutionModuleDescriptor> listExecutionModuleDescriptors() {
74 return modulesManager.listExecutionModules();
75 }
76
77 public boolean ping() {
78 return true;
79 }
80
81 /*
82 * BEAN
83 */
84 public void setModulesManager(ExecutionModulesManager modulesManager) {
85 this.modulesManager = modulesManager;
86 }
87
88 protected SlcAgentDescriptor getAgentDescriptor() {
89 return agentDescriptor;
90 }
91
92 public String getAgentUuid() {
93 return agentDescriptor.getUuid();
94 }
95
96 @Override
97 public String toString() {
98 return agentDescriptor.toString();
99 }
100 }