@@ -0,0 +1,3427 @@
+package io.cloudslang.content.utilities.services.localping;%0A%0Aimport io.cloudslang.content.constants.ReturnCodes;%0Aimport io.cloudslang.content.utilities.entities.LocalPingInputs;%0Aimport io.cloudslang.content.utilities.entities.OsDetectorInputs;%0Aimport io.cloudslang.content.utilities.services.osdetector.LocalOsDetectorService;%0Aimport io.cloudslang.content.utilities.services.osdetector.OsDetectorHelperService;%0Aimport org.jetbrains.annotations.NotNull;%0A%0Aimport java.io.BufferedReader;%0Aimport java.io.IOException;%0Aimport java.io.InputStreamReader;%0Aimport java.util.Map;%0A%0Aimport static io.cloudslang.content.constants.OutputNames.RETURN_CODE;%0Aimport static io.cloudslang.content.utilities.entities.constants.LocalPingConstants.HUNDRED_PERCENT_LOSS;%0Aimport static io.cloudslang.content.utilities.entities.constants.LocalPingConstants.PERCENTAGE_PACKETS_LOST;%0Aimport static org.apache.commons.lang3.StringUtils.isEmpty;%0A%0A/**%0A * Created by pinteae on 1/10/2018.%0A */%0Apublic class LocalPingService %7B%0A%0A    private static final String LOCALHOST = %22127.0.0.1%22;%0A    private static final String OTHER = %22other%22;%0A    private static final String UNABLE_TO_DETECT_LOCAL_OPERATING_SYSTEM = %22Unable to detect local operating system.%22;%0A%0A    public Map%3CString, String%3E executePingCommand(LocalPingInputs localPingInputs) throws IOException %7B%0A        String osFamily = detectOsFamily(LOCALHOST);%0A%0A        if (osFamily == null %7C%7C osFamily.equalsIgnoreCase(OTHER)) %7B%0A            throw new RuntimeException(UNABLE_TO_DETECT_LOCAL_OPERATING_SYSTEM);%0A        %7D%0A%0A        LocalPingCommand localPingCommand = LocalPingCommandFactory.getLocalPingCommand(osFamily);%0A%0A        String command = localPingCommand.createCommand(localPingInputs);%0A%0A        Map%3CString, String%3E resultsMap = localPingCommand.parseOutput(executeCommand(command));%0A        if (pingSucceeded(resultsMap.get(PERCENTAGE_PACKETS_LOST))) %7B%0A            resultsMap.put(RETURN_CODE, ReturnCodes.SUCCESS);%0A        %7D else %7B%0A            resultsMap.put(RETURN_CODE, ReturnCodes.FAILURE);%0A        %7D%0A%0A        return resultsMap;%0A    %7D%0A%0A    @NotNull%0A    private String executeCommand(String command) throws IOException %7B%0A        Process process = Runtime.getRuntime().exec(command);%0A        BufferedReader inputStream = new BufferedReader(new InputStreamReader(process.getInputStream()));%0A%0A        StringBuilder output = new StringBuilder();%0A        String currentLine;%0A        while ((currentLine = inputStream.readLine()) != null) %7B%0A            output.append(currentLine)%0A                    .append(System.lineSeparator());%0A        %7D%0A        return output.toString();%0A    %7D%0A%0A    private boolean pingSucceeded(String percentageLost) %7B%0A        boolean succeeded = true;%0A        if (isEmpty(percentageLost)) %7B%0A            succeeded = false;%0A        %7D else if (percentageLost.equalsIgnoreCase(HUNDRED_PERCENT_LOSS)) %7B%0A            succeeded = false;%0A        %7D%0A%0A        return succeeded;%0A    %7D%0A%0A    private String detectOsFamily(String host) %7B%0A        OsDetectorHelperService osDetectorHelperService = new OsDetectorHelperService();%0A        LocalOsDetectorService localOsDetectorService = new LocalOsDetectorService(osDetectorHelperService);%0A        OsDetectorInputs osDetectorInputs = new OsDetectorInputs.Builder()%0A                .withHost(host)%0A                .build();%0A%0A        return osDetectorHelperService.resolveOsFamily(localOsDetectorService.detectOs(osDetectorInputs).getFamily());%0A    %7D%0A%7D%0A

Implement Ping service