Utils { public static InstallationDetails createInstallationDetails(final MachineDetails md, final Cloud cloud, final ComputeTemplate template, final ExactZonesConfig zones, final String lookupLocatorsString, final Admin admin, final boolean isManagement, final File cloudFile, final GSAReservationId reservationId, final String templateName, final String securityProfile, final String keystorePassword, final String authGroups, final boolean rebootstrapping, final boolean isNoManagementSpace) throws FileNotFoundException { final InstallationDetails details = new InstallationDetails(); details.setBindToPrivateIp(cloud.getConfiguration().isConnectToPrivateIp()); details.setLocalDir(template.getAbsoluteUploadDir()); details.setRelativeLocalDir(template.getLocalDirectory()); details.setLocationId(md.getLocationId()); final String remoteDir = template.getRemoteDirectory(); details.setRemoteDir(remoteDir); final List<String> managementOnlyFiles = new ArrayList<String>(cloud.getProvider().getManagementOnlyFiles()); if (template.getKeyFile() != null) { managementOnlyFiles.add(template.getKeyFile()); } details.setManagementOnlyFiles(managementOnlyFiles); details.setZones(StringUtils.collectionToCommaDelimitedString(zones.getZones())); details.setPrivateIp(md.getPrivateAddress()); details.setPublicIp(md.getPublicAddress()); details.setLocator(lookupLocatorsString); details.setCloudifyUrl(cloud.getProvider().getCloudifyUrl()); details.setOverridesUrl(cloud.getProvider().getCloudifyOverridesUrl()); details.setConnectedToPrivateIp(cloud.getConfiguration().isConnectToPrivateIp()); details.setAdmin(admin); details.setUsername(md.getRemoteUsername()); details.setPassword(md.getRemotePassword()); details.setRemoteExecutionMode(md.getRemoteExecutionMode()); details.setFileTransferMode(md.getFileTransferMode()); details.setScriptLanguage(md.getScriptLangeuage()); details.setCloudFile(cloudFile); details.setManagement(isManagement); details.setAutoRestartAgent(Boolean.toString(template.getAutoRestartAgent())); final GridComponents componentsConfig = cloud.getConfiguration().getComponents(); GridCommandLineBuilder gridCommandBuilder = new GridCommandLineBuilder(); if (isManagement) { details.setConnectedToPrivateIp(!cloud.getConfiguration().isBootstrapManagementOnPublicIp()); details.setSecurityProfile(securityProfile); details.setKeystorePassword(keystorePassword); final String esmCommandlineArgs = gridCommandBuilder.getEsmCommandlineArgs(componentsConfig.getOrchestrator(), rebootstrapping, isNoManagementSpace); final String lusCommandlineArgs = gridCommandBuilder.getLusCommandlineArgs(componentsConfig.getDiscovery(), lookupLocatorsString); final String gsmCommandlineArgs = gridCommandBuilder.getGsmCommandlineArgs(cloud, lookupLocatorsString, componentsConfig.getDeployer(), componentsConfig.getDiscovery()); details.setEsmCommandlineArgs(esmCommandlineArgs); details.setLusCommandlineArgs(lusCommandlineArgs); details.setGsmCommandlineArgs(gsmCommandlineArgs); details.setGscLrmiPortRange(componentsConfig.getUsm().getPortRange()); details.setRestPort(componentsConfig.getRest().getPort()); details.setWebuiPort(componentsConfig.getWebui().getPort()); details.setRestMaxMemory(componentsConfig.getRest().getMaxMemory()); details.setWebuiMaxMemory(componentsConfig.getWebui().getMaxMemory()); } else { details.setConnectedToPrivateIp(cloud.getConfiguration().isConnectToPrivateIp()); } details.setAttributesStoreDiscoveryTimeout( componentsConfig.getUsm().getAttributesStoreDiscoveryTimeoutInSeconds()); String agentCommandlineArgs = gridCommandBuilder.getAgentCommandlineArgs(componentsConfig.getAgent(), details.isManagement() ? MANAGEMENT_ZONE : details.getZones(), reservationId); details.setGsaCommandlineArgs(agentCommandlineArgs); final Set<Entry<String, Object>> customEntries = template.getCustom().entrySet(); for (final Entry<String, Object> entry : customEntries) { if (entry.getKey().startsWith("installer.")) { details.getCustomData().put(entry.getKey(), entry.getValue()); } } if (md.getKeyFile() != null) { details.setKeyFile(md.getKeyFile().getAbsolutePath()); } else { final String keyFileName = template.getKeyFile(); if (!org.apache.commons.lang.StringUtils.isBlank(keyFileName)) { File keyFile = new File(keyFileName); if (!keyFile.isAbsolute()) { keyFile = new File(details.getLocalDir(), keyFileName); } if (!keyFile.isFile()) { throw new FileNotFoundException( "Could not find key file matching specified cloud configuration key file: " + template.getKeyFile() + ". Tried: " + keyFile + " but file does not exist"); } details.setKeyFile(keyFile.getAbsolutePath()); } } if (template.getHardwareId() != null) { details.getExtraRemoteEnvironmentVariables().put(CloudifyConstants.GIGASPACES_CLOUD_HARDWARE_ID, template.getHardwareId()); details.getExtraRemoteEnvironmentVariables().put(CloudifyConstants.CLOUDIFY_CLOUD_HARDWARE_ID, template.getHardwareId()); } if (template.getImageId() != null) { details.getExtraRemoteEnvironmentVariables().put(CloudifyConstants.GIGASPACES_CLOUD_IMAGE_ID, template.getImageId()); details.getExtraRemoteEnvironmentVariables().put(CloudifyConstants.CLOUDIFY_CLOUD_IMAGE_ID, template.getImageId()); } details.getExtraRemoteEnvironmentVariables().put(CloudifyConstants.GIGASPACES_AGENT_ENV_PRIVILEGED, Boolean.toString(template.isPrivileged())); if (!org.apache.commons.lang.StringUtils.isBlank(template.getInitializationCommand())) { details.getExtraRemoteEnvironmentVariables().put(CloudifyConstants.GIGASPACES_AGENT_ENV_INIT_COMMAND, template.getInitializationCommand()); } final Set<Entry<String, String>> entries = template.getEnv().entrySet(); for (final Entry<String, String> entry : entries) { details.getExtraRemoteEnvironmentVariables().put(entry.getKey(), entry.getValue()); } if (!org.apache.commons.lang.StringUtils.isBlank(template.getJavaUrl())) { details.getExtraRemoteEnvironmentVariables().put(CloudifyConstants.GIGASPACES_AGENT_ENV_JAVA_URL, template.getJavaUrl()); } details.setReservationId(reservationId); details.setTemplateName(templateName); details.setMachineId(md.getMachineId()); if (authGroups != null) { details.setAuthGroups(authGroups); } details.setDeleteRemoteDirectoryContents(md.isCleanRemoteDirectoryOnStart()); details.setPersistent(cloud.getConfiguration().getPersistentStoragePath() != null); if (md.getInstallerConfiguration() != null) { details.setInstallerConfiguration(md.getInstallerConfiguration()); } else { details.setInstallerConfiguration(template.getInstaller()); } details.setOpenFilesLimit(md.getOpenFilesLimit()); if (md.getEnvironment() != null && !md.getEnvironment().isEmpty()) { final Set<Entry<String, String>> environmentEntries = md.getEnvironment().entrySet(); for (Entry<String, String> entry : environmentEntries) { details.getExtraRemoteEnvironmentVariables().put(entry.getKey(), entry.getValue()); } } logger.fine("Created InstallationDetails: " + details); return details; } private  Utils(); static int getInteger(final Object obj, final int defaultValue); static boolean getBoolean(final Object obj, final boolean defaultValue); static Admin getAdminObject(final String managementIP, final int expectedGsmCount, final Integer lusPort); static void executeSSHCommand(final String host, final String command, final String username,
			final String password, final String keyFile, final long timeout, final TimeUnit unit); static InstallationDetails createInstallationDetails(final MachineDetails md,
			final Cloud cloud, final ComputeTemplate template, final ExactZonesConfig zones,
			final String lookupLocatorsString, final Admin admin,
			final boolean isManagement,
			final File cloudFile,
			final GSAReservationId reservationId,
			final String templateName,
			final String securityProfile,
			final String keystorePassword,
			final String authGroups, final boolean rebootstrapping, final boolean isNoManagementSpace); static File createTempFolder(); static int getFileTransferPort(final CloudTemplateInstallerConfiguration installerConfiguration,
			final FileTransferModes mode); static int getRemoteExecutionPort(final CloudTemplateInstallerConfiguration installerConfiguration,
			final RemoteExecutionModes mode); static SSHClient createSSHClient(final InstallationDetails details, final String host, final int port); static void threadSleep(long time);  }
@Test public void testCreateInstallationDetailsWithMachineDetailsEnvironment() throws Exception { final MachineDetails md = new MachineDetails(); md.getEnvironment().put("MARKER", "MARKER_VALUE"); final Cloud cloud = new Cloud(); cloud.getProvider().setManagementOnlyFiles(new ArrayList<String>()); final ComputeTemplate template = new ComputeTemplate(); final ExactZonesConfig zones = new ExactZonesConfig(); zones.setZones(new HashSet<String>(Arrays.asList("Zone1"))); final File cloudFile = new File("no-cloud.groovy"); final GSAReservationId reservationId = new GSAReservationId("123456"); final String templateName = "SMALL_LINUX"; final InstallationDetails result = Utils.createInstallationDetails(md, cloud, template, zones, "localhost:4177", null, false, cloudFile, reservationId, templateName, null, null, null, false, false); Assert.assertNotNull(result.getExtraRemoteEnvironmentVariables()); Assert.assertTrue("Expected to find environment variable", result.getExtraRemoteEnvironmentVariables() .containsKey("MARKER")); Assert.assertEquals("MARKER_VALUE", result.getExtraRemoteEnvironmentVariables().get("MARKER")); }