|
| 1 | +package noe.ews.workspace |
| 2 | + |
| 3 | +import groovy.util.logging.Slf4j |
| 4 | +import noe.common.DefaultProperties |
| 5 | +import noe.common.utils.Cleaner |
| 6 | +import noe.common.utils.JBFile |
| 7 | +import noe.common.utils.Library |
| 8 | +import noe.common.utils.Version |
| 9 | +import noe.ews.server.tomcat.TomcatProperties |
| 10 | +import noe.ews.utils.EwsUtils |
| 11 | +import noe.jbcs.utils.HttpdHelper |
| 12 | +import noe.server.Httpd |
| 13 | +import noe.workspace.WorkspaceApacheDS |
| 14 | +import noe.workspace.WorkspaceHttpd |
| 15 | +import noe.workspace.WorkspaceMultipleTomcats |
| 16 | +import noe.workspace.WorkspaceTomcat |
| 17 | + |
| 18 | +/** |
| 19 | + * This workspace allow you to have multiple tomcats and a single httpd |
| 20 | + * @author Paul Lodge |
| 21 | + */ |
| 22 | + |
| 23 | +@Slf4j |
| 24 | +class WorkspaceMultipleTomcatsHttpd extends WorkspaceMultipleTomcats { |
| 25 | + |
| 26 | + int numberOfAdditionalTomcats |
| 27 | + |
| 28 | + protected static WorkspaceHttpd workspaceHttpd |
| 29 | + protected static WorkspaceTomcat workspaceTomcat |
| 30 | + protected static WorkspaceApacheDS workspaceApacheDS |
| 31 | + |
| 32 | + protected EwsUtils ewsW |
| 33 | + |
| 34 | + Boolean ews |
| 35 | + Boolean rpm |
| 36 | + Version ewsVersion |
| 37 | + Boolean skipEwsPostinstall |
| 38 | + String hostIpAddress = DefaultProperties.HOST |
| 39 | + Map originalTomcatHosts = [:] |
| 40 | + |
| 41 | + WorkspaceHttpdEws(int numberOfAdditionalTomcats = 0) { |
| 42 | + super() |
| 43 | + this.numberOfAdditionalTomcats = numberOfAdditionalTomcats |
| 44 | + |
| 45 | + workspaceHttpd = new WorkspaceHttpd() |
| 46 | + workspaceTomcat = new WorkspaceTomcat() |
| 47 | + workspaceApacheDS = new WorkspaceApacheDS() |
| 48 | + // we want multiple instances, baseline needs to be without postinstall being already executed, |
| 49 | + // we will execute it later on ourselves after having created copies |
| 50 | + workspaceHttpd.skipHttpdPostInstall = true |
| 51 | + |
| 52 | + this.ews = Boolean.valueOf(Library.getUniversalProperty('ews', 'true')) |
| 53 | + this.ewsVersion = DefaultProperties.ewsVersion() |
| 54 | + this.skipEwsPostinstall = Boolean.valueOf(Library.getUniversalProperty('ews.postinstall.skip', 'false')) |
| 55 | + this.rpm = Boolean.valueOf(Library.getUniversalProperty('ews.rpm', 'false')) |
| 56 | + |
| 57 | + initWorkspaceEws() |
| 58 | + } |
| 59 | + |
| 60 | + def prepare() { |
| 61 | + log.info('Executing prepare for WorkspaceHttpdTomcats.') |
| 62 | + super.prepare() |
| 63 | + |
| 64 | + workspaceHttpd.prepare() |
| 65 | + if (platform.isWindows()) { |
| 66 | + serverController.installApacheWindowsService(serverController.getHttpdServerId()) |
| 67 | + } |
| 68 | + |
| 69 | + boolean purge = (ewsVersion >= new Version('3.1.0-DR0')) || (DefaultProperties.apacheCoreVersion() != null) |
| 70 | + workspaceTomcat.prepare(purge) |
| 71 | + workspaceApacheDS.prepare() |
| 72 | + |
| 73 | + /** |
| 74 | + * Tomcats |
| 75 | + */ |
| 76 | + createAdditionalTomcatsWithRegistrations(numberOfAdditionalTomcats) |
| 77 | + |
| 78 | + if (!context.areInSingleGroup(["jbcs", "rpm"])) { |
| 79 | + serverController.getHttpdServerIds().each { httpdServerId -> |
| 80 | + log.debug("EWS: httpdBasedir:${httpdServerId}") |
| 81 | + Httpd httpd = serverController.getServerById(httpdServerId) |
| 82 | + HttpdHelper httpdHelper = new HttpdHelper(platform) |
| 83 | + httpdHelper.runPostinstall(httpd) |
| 84 | + |
| 85 | + |
| 86 | + if (platform.isWindows()) { |
| 87 | + serverController.installApacheWindowsService(httpdServerId) |
| 88 | + } else { |
| 89 | + def tmpHttpd = serverController.getServerById(httpdServerId) |
| 90 | + JBFile.makeAccessible(new File(tmpHttpd.basedir + "/" + tmpHttpd.binPath + "/apachectl")) |
| 91 | + if (tmpHttpd.getVersion() < new Version("2.4")) { |
| 92 | + // httpd2.2 in EWS2.1 |
| 93 | + JBFile.makeAccessible(new File(tmpHttpd.basedir + "/" + tmpHttpd.binPath + "/httpd.worker")) |
| 94 | + if (!platform.isSolaris()) { |
| 95 | + JBFile.makeAccessible(new File(tmpHttpd.basedir + "/" + tmpHttpd.binPath + "/httpd")) |
| 96 | + } |
| 97 | + } else { |
| 98 | + // httpd2.4 in JWS3.0 |
| 99 | + JBFile.makeAccessible(new File(tmpHttpd.basedir + "/" + tmpHttpd.binPath + "/httpd")) |
| 100 | + // Logdir is a symlink to /var/log/httpd |
| 101 | + tmpHttpd.logDirs.each { String logdir -> |
| 102 | + JBFile.makeAccessible(new File(tmpHttpd.basedir + "/" + logdir)) |
| 103 | + } |
| 104 | + } |
| 105 | + } |
| 106 | + } |
| 107 | + |
| 108 | + if (!skipEwsPostinstall) { |
| 109 | + installEws() |
| 110 | + } |
| 111 | + } |
| 112 | + |
| 113 | + Httpd httpd = serverController.getServerById(serverController.getHttpdServerId()) as Httpd |
| 114 | + httpd.setHost(hostIpAddress) |
| 115 | + httpd.updateConfSetBindAddress(hostIpAddress) |
| 116 | + |
| 117 | + originalTomcatHosts.putAll(originalTomcatHostsIpAddresses()) |
| 118 | + |
| 119 | + serverController.backup() |
| 120 | + |
| 121 | + log.info('Creating of new WorkspaceHttpdTomcats has finished.') |
| 122 | + } |
| 123 | + |
| 124 | + def destroy() { |
| 125 | + log.info('Destroying of WorkspaceHttpdTomcats has started.') |
| 126 | + if (platform.isWindows()) { |
| 127 | + serverController.uninstallWindowsServices() |
| 128 | + } |
| 129 | + |
| 130 | + String httpdServerId = serverController.getHttpdServerId() |
| 131 | + serverController.getServerById(httpdServerId).setHost(hostIpAddress) |
| 132 | + |
| 133 | + serverController.getTomcatServerIds([TomcatProperties.TOMCAT_MAJOR_VERSION]).each { String tomcatId -> |
| 134 | + serverController.getServerById(tomcatId).setHost(originalTomcatHosts.get(tomcatId) as String) |
| 135 | + } |
| 136 | + |
| 137 | + super.destroy() |
| 138 | + |
| 139 | + workspaceHttpd?.destroy() |
| 140 | + workspaceTomcat?.destroy() |
| 141 | + workspaceApacheDS?.destroy() |
| 142 | + |
| 143 | + // TODO HP And no basedir was set?? |
| 144 | + // What about Testing standalone tomcats (this.ews should be sufficient) |
| 145 | + if (this.ews && !this.rpm && !this.skipInstall) { |
| 146 | + if (deleteWorkspace) { |
| 147 | + Cleaner.cleanDirectoryBasedOnRegex(new File(getBasedir()), /.*(jws|jboss-ews|jbcs).*/) |
| 148 | + log.info('EWS workspace deleted: ' + basedir) |
| 149 | + } |
| 150 | + log.info('EWS workspace NOT deleted: ' + basedir) |
| 151 | + } |
| 152 | + |
| 153 | + workspaceHttpd = null |
| 154 | + workspaceTomcat = null |
| 155 | + workspaceApacheDS = null |
| 156 | + } |
| 157 | + |
| 158 | + /** |
| 159 | + * Initialize the workspace. |
| 160 | + */ |
| 161 | + void initWorkspaceEws() { |
| 162 | + log.info('WorkspaceEws.initWorkspaceEws(): BEGIN') |
| 163 | + |
| 164 | + // Are the paths valid? |
| 165 | + // TODO validate tomcat paths (nodenames) |
| 166 | + def validPaths = Library.validatePaths([ |
| 167 | + basedir, |
| 168 | + workspaceHttpd.basedirHttpd |
| 169 | + ]) |
| 170 | + if (!validPaths.isEmpty()) { |
| 171 | + // TODO LP How to better handle this? |
| 172 | + throw new RuntimeException('Invalid paths' + validPaths.toString()) |
| 173 | + } |
| 174 | + |
| 175 | + // TODO validate ews installation |
| 176 | + |
| 177 | + log.info('WorkspaceEws.initWorkspaceEws(): END') |
| 178 | + } |
| 179 | + |
| 180 | + /** |
| 181 | + * Unzips Hibernate Library archive in src/main/resources/hibernate/library |
| 182 | + * Downloads JDBC drivers |
| 183 | + */ |
| 184 | + void prepareHibernate(Boolean unzipHibernate = true) { |
| 185 | + ewsW = new EwsUtils() |
| 186 | + |
| 187 | + if (unzipHibernate) { |
| 188 | + ewsW.unzipHibernateLibrary() |
| 189 | + } |
| 190 | + |
| 191 | + ewsW.downloadJDBCDriver() |
| 192 | + } |
| 193 | + |
| 194 | + /** |
| 195 | + * Remove Hibernate Library and JDBC driver from resources |
| 196 | + */ |
| 197 | + void cleanupHibernate() { |
| 198 | + ewsW = new EwsUtils() |
| 199 | + ewsW.removeUnzippedHibernateLib() |
| 200 | + ewsW.removeJDBCDriver() |
| 201 | + } |
| 202 | + |
| 203 | + /** |
| 204 | + * Install EWS |
| 205 | + * Static dir expected. |
| 206 | + * |
| 207 | + * @see GetEWS.getIt ( ) |
| 208 | + */ |
| 209 | + void installEws() { |
| 210 | + if (!this.context.areInSingleGroup(['ews', 'rpm'])) { |
| 211 | + log.info('Installing EWS zip distribution') |
| 212 | + ewsW = new EwsUtils() |
| 213 | + if (platform.isSolaris() && JBFile.useAdminPrivileges) { |
| 214 | + serverController.getHttpdServerIds().each { httpdId -> |
| 215 | + Httpd httpd = (Httpd) serverController.getServerById(httpdId) |
| 216 | + HttpdHelper.setEolOnSolarisHttpd(httpd) |
| 217 | + } |
| 218 | + } |
| 219 | + } |
| 220 | + } |
| 221 | + |
| 222 | + /** |
| 223 | + * Implementing of groovy fallback missingProperty. |
| 224 | + * |
| 225 | + * @link http://groovy.codehaus.org/Using+methodMissing+and+propertyMissing |
| 226 | + */ |
| 227 | + def propertyMissing(String name) { |
| 228 | + if (workspaceHttpd.hasProperty(name)) { |
| 229 | + workspaceHttpd.name |
| 230 | + } else if (workspaceTomcat.hasProperty(name)) { |
| 231 | + workspaceTomcat.name |
| 232 | + } else if (workspaceApacheDS.hasProperty(name)) { |
| 233 | + workspaceApacheDS.name |
| 234 | + } else throw new RuntimeException("WorkspaceHttpdTomcats.propertyMissing(): WorkspaceHttpd nor WorkspaceTomcat has property $name") |
| 235 | + } |
| 236 | +} |
0 commit comments