Search in sources :

Example 1 with ProcessId

use of org.sonar.process.ProcessId in project sonarqube by SonarSource.

the class ProcessLauncherImpl method launchJava.

private <T extends JvmOptions> Process launchJava(JavaCommand<T> javaCommand) {
    ProcessId processId = javaCommand.getProcessId();
    try {
        ProcessBuilder processBuilder = create(javaCommand);
        logLaunchedCommand(javaCommand, processBuilder);
        return processBuilder.start();
    } catch (Exception e) {
        throw new IllegalStateException(format("Fail to launch process [%s]", processId.getKey()), e);
    }
}
Also used : ProcessId(org.sonar.process.ProcessId) IOException(java.io.IOException)

Example 2 with ProcessId

use of org.sonar.process.ProcessId in project sonarqube by SonarSource.

the class ProcessLauncherImpl method launch.

public ManagedProcess launch(AbstractCommand command) {
    EsInstallation esInstallation = command.getEsInstallation();
    if (esInstallation != null) {
        cleanupOutdatedEsData(esInstallation);
        writeConfFiles(esInstallation);
    }
    Process process;
    if (command instanceof EsScriptCommand) {
        process = launchExternal((EsScriptCommand) command);
    } else if (command instanceof JavaCommand) {
        process = launchJava((JavaCommand<?>) command);
    } else {
        throw new IllegalStateException("Unexpected type of command: " + command.getClass());
    }
    ProcessId processId = command.getProcessId();
    try {
        if (processId == ProcessId.ELASTICSEARCH) {
            checkArgument(esInstallation != null, "Incorrect configuration EsInstallation is null");
            EsConnectorImpl esConnector = new EsConnectorImpl(singleton(HostAndPort.fromParts(esInstallation.getHost(), esInstallation.getHttpPort())), esInstallation.getBootstrapPassword());
            return new EsManagedProcess(process, processId, esConnector);
        } else {
            ProcessCommands commands = allProcessesCommands.createAfterClean(processId.getIpcIndex());
            return new ProcessCommandsManagedProcess(process, processId, commands);
        }
    } catch (Exception e) {
        // just in case
        if (process != null) {
            process.destroyForcibly();
        }
        throw new IllegalStateException(format("Fail to launch monitor of process [%s]", processId.getKey()), e);
    }
}
Also used : JavaCommand(org.sonar.application.command.JavaCommand) EsInstallation(org.sonar.application.es.EsInstallation) EsScriptCommand(org.sonar.application.command.EsScriptCommand) ProcessCommands(org.sonar.process.sharedmemoryfile.ProcessCommands) EsManagedProcess(org.sonar.application.process.EsManagedProcess) ProcessCommandsManagedProcess(org.sonar.application.process.ProcessCommandsManagedProcess) ManagedProcess(org.sonar.application.process.ManagedProcess) ProcessId(org.sonar.process.ProcessId) EsConnectorImpl(org.sonar.application.es.EsConnectorImpl) ProcessCommandsManagedProcess(org.sonar.application.process.ProcessCommandsManagedProcess) EsManagedProcess(org.sonar.application.process.EsManagedProcess) IOException(java.io.IOException)

Example 3 with ProcessId

use of org.sonar.process.ProcessId in project sonarqube by SonarSource.

the class SchedulerImpl method schedule.

@Override
public void schedule() throws InterruptedException {
    if (!nodeLifecycle.tryToMoveTo(NodeLifecycle.State.STARTING)) {
        return;
    }
    firstWaitingEsLog.set(true);
    processesById.clear();
    for (ProcessId processId : ClusterSettings.getEnabledProcesses(settings)) {
        ManagedProcessHandler process = ManagedProcessHandler.builder(processId).addProcessLifecycleListener(this).addEventListener(this).setWatcherDelayMs(processWatcherDelayMs).setStopTimeout(stopTimeoutFor(processId, settings)).setHardStopTimeout(HARD_STOP_TIMEOUT).setAppSettings(settings).build();
        processesById.put(process.getProcessId(), process);
    }
    operationalCountDown.set(processesById.size());
    tryToStartAll();
}
Also used : ManagedProcessHandler(org.sonar.application.process.ManagedProcessHandler) ProcessId(org.sonar.process.ProcessId)

Example 4 with ProcessId

use of org.sonar.process.ProcessId in project sonarqube by SonarSource.

the class HazelcastMemberBuilder method build.

public HazelcastMember build() {
    Config config = new Config();
    // do not use the value defined by property sonar.cluster.name.
    // Hazelcast does not fail when joining a cluster with different name.
    // Apparently this behavior exists since Hazelcast 3.8.2 (see note
    // at http://docs.hazelcast.org/docs/3.8.6/manual/html-single/index.html#creating-cluster-groups)
    config.setClusterName("SonarQube");
    // Configure network
    NetworkConfig netConfig = config.getNetworkConfig();
    netConfig.setPort(port).setPortAutoIncrement(false).setReuseAddress(true);
    netConfig.getInterfaces().setEnabled(true).setInterfaces(singletonList(requireNonNull(networkInterface, "Network interface is missing")));
    JoinConfig joinConfig = netConfig.getJoin();
    joinConfig.getAwsConfig().setEnabled(false);
    joinConfig.getMulticastConfig().setEnabled(false);
    if (KUBERNETES.equals(type)) {
        joinConfig.getKubernetesConfig().setEnabled(true).setProperty("service-dns", requireNonNull(members, "Service DNS is missing")).setProperty("service-port", CLUSTER_NODE_HZ_PORT.getDefaultValue());
    } else {
        List<String> addressesWithDefaultPorts = Stream.of(this.members.split(",")).filter(host -> !host.isBlank()).map(String::trim).map(HazelcastMemberBuilder::applyDefaultPortToHost).collect(Collectors.toList());
        joinConfig.getTcpIpConfig().setEnabled(true);
        joinConfig.getTcpIpConfig().setMembers(requireNonNull(addressesWithDefaultPorts, "Members are missing"));
    }
    // We are not using the partition group of Hazelcast, so disabling it
    config.getPartitionGroupConfig().setEnabled(false);
    // Tweak HazelCast configuration
    config.setProperty("hazelcast.tcp.join.port.try.count", "10").setProperty("hazelcast.socket.bind.any", "false").setProperty("hazelcast.phone.home.enabled", "false").setProperty("hazelcast.logging.type", "slf4j");
    MemberAttributeConfig attributes = config.getMemberAttributeConfig();
    attributes.setAttribute(Attribute.NODE_NAME.getKey(), requireNonNull(nodeName, "Node name is missing"));
    attributes.setAttribute(Attribute.PROCESS_KEY.getKey(), requireNonNull(processId, "Process key is missing").getKey());
    return new HazelcastMemberImpl(Hazelcast.newHazelcastInstance(config));
}
Also used : ProcessId(org.sonar.process.ProcessId) Config(com.hazelcast.config.Config) MemberAttributeConfig(com.hazelcast.config.MemberAttributeConfig) KUBERNETES(org.sonar.process.cluster.hz.JoinConfigurationType.KUBERNETES) Collectors(java.util.stream.Collectors) Attribute(org.sonar.process.cluster.hz.HazelcastMember.Attribute) String.format(java.lang.String.format) Collections.singletonList(java.util.Collections.singletonList) NetworkConfig(com.hazelcast.config.NetworkConfig) List(java.util.List) Stream(java.util.stream.Stream) CLUSTER_NODE_HZ_PORT(org.sonar.process.ProcessProperties.Property.CLUSTER_NODE_HZ_PORT) JoinConfig(com.hazelcast.config.JoinConfig) Hazelcast(com.hazelcast.core.Hazelcast) Objects.requireNonNull(java.util.Objects.requireNonNull) Config(com.hazelcast.config.Config) MemberAttributeConfig(com.hazelcast.config.MemberAttributeConfig) NetworkConfig(com.hazelcast.config.NetworkConfig) JoinConfig(com.hazelcast.config.JoinConfig) NetworkConfig(com.hazelcast.config.NetworkConfig) JoinConfig(com.hazelcast.config.JoinConfig) MemberAttributeConfig(com.hazelcast.config.MemberAttributeConfig)

Aggregations

ProcessId (org.sonar.process.ProcessId)4 IOException (java.io.IOException)2 Config (com.hazelcast.config.Config)1 JoinConfig (com.hazelcast.config.JoinConfig)1 MemberAttributeConfig (com.hazelcast.config.MemberAttributeConfig)1 NetworkConfig (com.hazelcast.config.NetworkConfig)1 Hazelcast (com.hazelcast.core.Hazelcast)1 String.format (java.lang.String.format)1 Collections.singletonList (java.util.Collections.singletonList)1 List (java.util.List)1 Objects.requireNonNull (java.util.Objects.requireNonNull)1 Collectors (java.util.stream.Collectors)1 Stream (java.util.stream.Stream)1 EsScriptCommand (org.sonar.application.command.EsScriptCommand)1 JavaCommand (org.sonar.application.command.JavaCommand)1 EsConnectorImpl (org.sonar.application.es.EsConnectorImpl)1 EsInstallation (org.sonar.application.es.EsInstallation)1 EsManagedProcess (org.sonar.application.process.EsManagedProcess)1 ManagedProcess (org.sonar.application.process.ManagedProcess)1 ManagedProcessHandler (org.sonar.application.process.ManagedProcessHandler)1