1 17 18 package org.sape.carbon.services.deployment; 19 20 import org.sape.carbon.core.component.ComponentConfiguration; 21 import org.sape.carbon.core.component.lifecycle.Configurable; 22 import org.sape.carbon.core.component.lifecycle.Startable; 23 import org.sape.carbon.core.component.lifecycle.Suspendable; 24 import org.sape.carbon.core.config.Config; 25 import org.sape.carbon.core.config.InvalidConfigurationException; 26 import org.sape.carbon.core.config.node.Folder; 27 import org.sape.carbon.core.config.node.Node; 28 import org.sape.carbon.core.config.node.NodeCreationException; 29 import org.sape.carbon.core.config.node.NodeNotFoundException; 30 import org.sape.carbon.core.config.node.NodeRemovalException; 31 import org.sape.carbon.core.config.node.link.GenericLinkNodeConfiguration; 32 import org.sape.carbon.core.config.node.link.GenericLinkNodeFactory; 33 34 import org.sape.carbon.services.deployment.namelookup.*; 35 36 46 public class DefaultDeploymentServiceImpl 47 implements DeploymentService, Configurable, Startable, Suspendable { 48 49 50 protected Folder deploymentsNode; 51 52 53 protected String currentDeploymentNodeName; 54 55 56 protected String targetNodeName; 57 58 62 public void configure(ComponentConfiguration configuration) 63 throws DeploymentServiceException { 64 65 DeploymentServiceConfiguration deploymentConfiguration = 66 (DeploymentServiceConfiguration) configuration; 67 68 try { 69 this.deploymentsNode = 70 (Folder) Config.getInstance().fetchNode( 71 deploymentConfiguration.getDeploymentsNodeAbsoluteName()); 72 } catch (NodeNotFoundException nnfe) { 73 throw new InvalidConfigurationException( 74 this.getClass(), 75 configuration.getConfigurationName(), 76 "DeploymentsNodeAbsoluteName", 77 nnfe); 78 } 79 80 this.currentDeploymentNodeName = 81 deploymentConfiguration.getCurrentDeploymentNodeName(); 82 83 this.targetNodeName = constructTargetNodeName(configuration); 84 } 85 86 90 public void start() throws DeploymentServiceException { 91 createDeploymentLink(); 92 } 93 94 97 public void stop() { 98 } 99 100 105 public void resume() throws DeploymentServiceException { 106 createDeploymentLink(); 109 } 110 111 114 public void suspend() { 115 } 116 117 124 protected void createDeploymentLink() 125 throws DeploymentServiceException { 126 127 try { 128 GenericLinkNodeConfiguration linkConfiguration = 129 (GenericLinkNodeConfiguration) Config 130 .getInstance() 131 .createConfiguration(GenericLinkNodeConfiguration.class); 132 133 linkConfiguration.setLinkNodeFactoryClass( 134 GenericLinkNodeFactory.class); 135 136 linkConfiguration.setTargetNodeName(this.targetNodeName); 137 138 if (this 139 .deploymentsNode 140 .containsChild(this.currentDeploymentNodeName)) { 141 142 this 143 .deploymentsNode 144 .fetchChild(this.currentDeploymentNodeName) 145 .remove(); 146 } 147 148 this.deploymentsNode.addLink( 149 this.currentDeploymentNodeName, 150 linkConfiguration); 151 152 } catch (NodeRemovalException nre) { 153 throw new DeploymentServiceException( 154 this.getClass(), 155 "Could not remove existing current deployment " 156 + "link: [" 157 + this.deploymentsNode.getAbsoluteName() 158 + Node.DELIMITER 159 + this.currentDeploymentNodeName 160 + "]", 161 nre); 162 163 } catch (NodeNotFoundException nnfe) { 164 throw new DeploymentServiceException( 167 this.getClass(), 168 "Inconsistent results from Folder: containsChild " 169 + "returned true, but fetch threw NodeNotFoundException", 170 nnfe); 171 172 } catch (NodeCreationException nce) { 173 throw new DeploymentServiceException( 174 this.getClass(), 175 "Could not create current deployment link: [" 176 + this.deploymentsNode.getAbsoluteName() 177 + Node.DELIMITER 178 + this.currentDeploymentNodeName 179 + "]", 180 nce); 181 } 182 } 183 184 196 protected String constructTargetNodeName( 197 ComponentConfiguration serviceConfig) throws DeploymentServiceException { 198 199 DeploymentServiceConfiguration deploymentConfiguration = 200 (DeploymentServiceConfiguration) serviceConfig; 201 202 String environmentName = deploymentConfiguration.getEnvironmentName(); 203 NameLookup environmentNameLookup = 204 deploymentConfiguration.getEnvironmentNameLookup(); 205 206 String instanceName = deploymentConfiguration.getInstanceName(); 207 NameLookup instanceNameLookup = 208 deploymentConfiguration.getInstanceNameLookup(); 209 210 if ((environmentName == null || "".equals(environmentName)) && 213 environmentNameLookup == null) { 214 throw new InvalidConfigurationException( 215 this.getClass(), 216 serviceConfig.getConfigurationName(), 217 "EnvironmentName or EnvironmentNameLookup", 218 "Neither EnvironmentName nor EnvironmentNameLookup were specified"); 219 } 220 221 if ((environmentName != null && !"".equals(environmentName)) && 223 environmentNameLookup != null) { 224 throw new InvalidConfigurationException( 225 this.getClass(), 226 serviceConfig.getConfigurationName(), 227 "EnvironmentName or EnvironmentNameLookup", 228 "Only one of EnvironmentName and EnvironmentNameLookup can be specified"); 229 } 230 231 if ((instanceName != null && !"".equals(instanceName)) && 233 instanceNameLookup != null) { 234 throw new InvalidConfigurationException( 235 this.getClass(), 236 serviceConfig.getConfigurationName(), 237 "InstanceName or InstanceNameLookup", 238 "Only one of InstanceName and InstanceNameLookup can be specified"); 239 } 240 241 StringBuffer nodeName = new StringBuffer (); 243 if (environmentNameLookup != null) { 244 nodeName.append(environmentNameLookup.lookupName()); 245 } else { 246 nodeName.append(environmentName); 247 } 248 249 if (instanceNameLookup != null) { 250 nodeName.append(Node.DELIMITER); 251 nodeName.append(instanceNameLookup.lookupName()); 252 } else if (instanceName != null && !"".equals(instanceName)) { 253 nodeName.append(Node.DELIMITER); 254 nodeName.append(instanceName); 255 } 256 257 return nodeName.toString(); 258 } 259 } | Popular Tags |