private void initPipelinesFolder() { File pipelines = new File(currentWorkingDirectory(), "pipelines"); if (!pipelines.exists()) { pipelines.mkdirs(); } } }
public static String emailBody() { String ip = SystemUtil.getFirstLocalNonLoopbackIpAddress(); String hostName = SystemUtil.getLocalhostName(); return String.format("You received this configuration test email from Go Server:\n\n%s (%s)\n\nThank you.", hostName, ip); }
public static boolean isLocalhost(String ipAddress) { return isLocalhost(ipAddress, ipAddress); }
public AgentController(SslInfrastructureService sslInfrastructureService, SystemEnvironment systemEnvironment, AgentRegistry agentRegistry, PluginManager pluginManager, SubprocessLogger subprocessLogger, AgentUpgradeService agentUpgradeService, AgentHealthHolder agentHealthHolder) { this.sslInfrastructureService = sslInfrastructureService; this.systemEnvironment = systemEnvironment; this.agentRegistry = agentRegistry; this.subprocessLogger = subprocessLogger; this.agentUpgradeService = agentUpgradeService; this.agentHealthHolder = agentHealthHolder; PluginManagerReference.reference().setPluginManager(pluginManager); hostName = SystemUtil.getLocalhostNameOrRandomNameIfNotFound(); ipAddress = SystemUtil.getClientIp(systemEnvironment.getServiceUrl()); }
public static SendEmailMessage backupFailedMessage(String exceptionMessage, String adminEmail) { String ipAddress = SystemUtil.getFirstLocalNonLoopbackIpAddress(); return new SendEmailMessage("Server Backup Failed",String.format("Backup of the Go server at '%s' has failed. The reason is: %s", ipAddress, exceptionMessage),adminEmail); }
public String clientName(File workingDir) { String hash = FileUtil.filesystemSafeFileHash(workingDir); return "cruise-" + SystemUtil.getLocalhostName() + "-" + workingDir.getName() + "-" + hash; }
public Validation validate(Validation validation) { if (SystemUtil.isLocalhostReachable(port)) { String message = format("Port {0} could not be opened. Please Check if it is available", String.valueOf(port)); return validation.addError(new RuntimeException(message)); } else { return Validation.SUCCESS; } } }
public static boolean reachable(String name, int port) { Socket s = null; try { s = new Socket(InetAddress.getByName(name), port); return true; } catch (Exception e) { return false; } finally { closeQuietly(s); } }
public static AgentRuntimeInfo fromServer(AgentConfig agentConfig, boolean registeredAlready, String location, Long usablespace, String operatingSystem, boolean supportsBuildCommandProtocol) { if (StringUtils.isEmpty(location)) { throw new RuntimeException("Agent should not register without installation path."); } AgentStatus status = AgentStatus.Pending; if (SystemUtil.isLocalIpAddress(agentConfig.getIpAddress()) || registeredAlready) { status = AgentStatus.Idle; } AgentRuntimeInfo agentRuntimeInfo = new AgentRuntimeInfo(agentConfig.getAgentIdentifier(), status.getRuntimeStatus(), location, null, supportsBuildCommandProtocol); agentRuntimeInfo.setUsableSpace(usablespace); agentRuntimeInfo.operatingSystemName = operatingSystem; return agentRuntimeInfo; }
private void register(AgentAutoRegistrationProperties agentAutoRegistrationProperties) throws Exception { String hostName = SystemUtil.getLocalhostNameOrRandomNameIfNotFound(); Registration keyEntry = Registration.createNullPrivateKeyEntry(); while (!keyEntry.isValid()) { try { getTokenIfNecessary(); keyEntry = remoteRegistrationRequester.requestRegistration(hostName, agentAutoRegistrationProperties); } catch (Exception e) { LOGGER.error("[Agent Registration] There was a problem registering with the go server.", e); throw e; } if ((!keyEntry.isValid())) { try { LOGGER.debug("[Agent Registration] Retrieved agent key from Go server is not valid."); Thread.sleep(REGISTER_RETRY_INTERVAL); } catch (InterruptedException e) { // Ok } } } LOGGER.info("[Agent Registration] Retrieved registration from Go server."); storeChainIntoAgentStore(keyEntry); agentAutoRegistrationProperties.scrubRegistrationProperties(); }
public static String getClientIp(String serviceUrl) { try { URL url = new URL(serviceUrl); int port = url.getPort(); if (port == -1) { port = url.getDefaultPort(); } try (Socket socket = new Socket(url.getHost(), port)) { return socket.getLocalAddress().getHostAddress(); } } catch (Exception e) { return SystemUtil.getFirstLocalNonLoopbackIpAddress(); } } }
@Test public void shouldReturnFalseIfPortIsNotReachableOnLocalhost() throws Exception { assertThat(SystemUtil.isLocalhostReachable(9876), is(false)); } }
private void initRuntimeInfo() { Boolean buildCommandProtocolEnabled = systemEnvironment.isBuildCommandProtocolEnabled(); agentAutoRegistrationProperties = new AgentAutoRegistrationPropertiesImpl(new File("config", "autoregister.properties")); if (agentAutoRegistrationProperties.isElastic()) { agentRuntimeInfo = ElasticAgentRuntimeInfo.fromAgent(identifier, AgentRuntimeStatus.Idle, currentWorkingDirectory(), agentAutoRegistrationProperties.agentAutoRegisterElasticAgentId(), agentAutoRegistrationProperties.agentAutoRegisterElasticPluginId()); } else { agentRuntimeInfo = AgentRuntimeInfo.fromAgent(identifier, AgentStatus.Idle.getRuntimeStatus(), currentWorkingDirectory(), buildCommandProtocolEnabled); } }
@Before public void setUp() throws Exception { agentIdentifier = new AgentIdentifier(getLocalhostName(), getFirstLocalNonLoopbackIpAddress(), agentUuid); }
public static SendEmailMessage noDatabaseDiskSpaceMessage(SystemEnvironment systemEnvironment, String adminMail, String targetFolder) { String ipAddress = SystemUtil.getFirstLocalNonLoopbackIpAddress(); return new SendEmailMessage( "No database disk space error message from Go Server at " + ipAddress, String.format( NO_DATABASE_DISK_SPACE_EMAIL, ipAddress, systemEnvironment.getDatabaseDiskSpaceFullLimit(), targetFolder), adminMail); }
public boolean isFromLocalHost() { if (cachedIsFromLocalHost == null) { cachedIsFromLocalHost = SystemUtil.isLocalhost(ipAddress); } return cachedIsFromLocalHost.booleanValue(); }
private AgentRuntimeInfo idleRuntimeInfo() { AgentRuntimeInfo agentRuntimeInfo = new AgentRuntimeInfo(agentConfig.getAgentIdentifier(), AgentRuntimeStatus.Idle, currentWorkingDirectory(), "cookie", false); agentRuntimeInfo.idle(); return agentRuntimeInfo; }
@Before public void setUp() throws Exception { agentIdentifier = new AgentIdentifier(getLocalhostName(), getFirstLocalNonLoopbackIpAddress(), agentUuid); }
public static SendEmailMessage noArtifactsDiskSpaceMessage(SystemEnvironment systemEnvironment, String adminMail, String targetFolder) { String ipAddress = SystemUtil.getFirstLocalNonLoopbackIpAddress(); long size = systemEnvironment.getArtifactReposiotryFullLimit(); return new SendEmailMessage( "No artifacts disk space error message from Go Server at " + ipAddress, String.format( NO_ARTIFACTS_DISK_SPACE_EMAIL, ipAddress, size, targetFolder), adminMail); }
@Test public void shouldDetermineIfAddressIsLocal() throws UnknownHostException { InetAddress local; try { local = InetAddress.getLocalHost(); } catch (UnknownHostException e) { local = InetAddress.getByName("localhost"); } assertThat("Localhost (" + local.getHostName() + ") should be a local address.", SystemUtil.isLocalhost(local.getHostAddress()), is(true)); }