├── .github └── workflows │ └── maven-publish.yml ├── .gitignore ├── README.md ├── demos ├── colors.gif ├── download-demo.gif ├── increase-size.gif ├── main-demo.gif └── save-demo.gif ├── pom.xml └── src └── main ├── java └── zos │ └── shell │ ├── ZosShell.java │ ├── command │ └── CommandRouter.java │ ├── constants │ └── Constants.java │ ├── controller │ ├── BrowseJobController.java │ ├── CancelController.java │ ├── ChangeConnController.java │ ├── ChangeDirController.java │ ├── ChangeWinController.java │ ├── ConcatController.java │ ├── ConsoleController.java │ ├── CopyController.java │ ├── CountController.java │ ├── DeleteController.java │ ├── DownloadDsnController.java │ ├── DownloadJobController.java │ ├── EchoController.java │ ├── EditController.java │ ├── EnvVariableController.java │ ├── GrepController.java │ ├── ListingController.java │ ├── LocalFilesController.java │ ├── MakeDirController.java │ ├── ProcessLstController.java │ ├── PurgeController.java │ ├── RenameController.java │ ├── SaveController.java │ ├── SearchCacheController.java │ ├── StopController.java │ ├── SubmitController.java │ ├── TailController.java │ ├── TouchController.java │ ├── TsoController.java │ ├── UnameController.java │ ├── UsermodController.java │ ├── UssController.java │ └── container │ │ ├── ContainerType.java │ │ ├── ControllerFactoryContainer.java │ │ └── Dependency.java │ ├── record │ └── DatasetMember.java │ ├── response │ └── ResponseStatus.java │ ├── service │ ├── autocomplete │ │ ├── SearchCommandService.java │ │ ├── TrieNode.java │ │ └── TriePreFix.java │ ├── change │ │ ├── ChangeConnService.java │ │ ├── ChangeDirService.java │ │ └── ChangeWinService.java │ ├── checksum │ │ └── CheckSumService.java │ ├── console │ │ ├── Console.java │ │ ├── ConsoleService.java │ │ └── FutureConsole.java │ ├── datasetlst │ │ ├── DatasetListingService.java │ │ └── FutureDatasetListing.java │ ├── dsn │ │ ├── concat │ │ │ ├── Concat.java │ │ │ ├── ConcatService.java │ │ │ └── FutureConcat.java │ │ ├── copy │ │ │ ├── Copy.java │ │ │ ├── CopyService.java │ │ │ └── FutureCopy.java │ │ ├── count │ │ │ └── CountService.java │ │ ├── delete │ │ │ ├── Delete.java │ │ │ ├── DeleteService.java │ │ │ └── FutureDelete.java │ │ ├── download │ │ │ ├── DatasetInfo.java │ │ │ ├── Download.java │ │ │ ├── DownloadAllMembersService.java │ │ │ ├── DownloadMemberListService.java │ │ │ ├── DownloadMemberService.java │ │ │ ├── DownloadMembersService.java │ │ │ ├── DownloadPdsMemberService.java │ │ │ ├── DownloadSeqDatasetService.java │ │ │ ├── FutureDatasetDownload.java │ │ │ ├── FutureDatasetInfo.java │ │ │ └── FutureMemberDownload.java │ │ ├── edit │ │ │ ├── Edit.java │ │ │ ├── EditService.java │ │ │ └── FutureEdit.java │ │ ├── list │ │ │ └── ListingService.java │ │ ├── makedir │ │ │ ├── FutureMakeDirectory.java │ │ │ ├── MakeDirService.java │ │ │ └── MakeDirectory.java │ │ ├── save │ │ │ ├── FutureSave.java │ │ │ ├── Save.java │ │ │ └── SaveService.java │ │ └── touch │ │ │ ├── FutureTouch.java │ │ │ ├── Touch.java │ │ │ └── TouchService.java │ ├── echo │ │ └── EchoService.java │ ├── env │ │ └── EnvVariableService.java │ ├── grep │ │ ├── FutureGrep.java │ │ ├── Grep.java │ │ └── GrepService.java │ ├── help │ │ └── HelpService.java │ ├── history │ │ ├── CircularLinkedList.java │ │ └── HistoryService.java │ ├── job │ │ ├── browse │ │ │ ├── BrowseLog.java │ │ │ ├── BrowseLogService.java │ │ │ └── FutureBrowseLog.java │ │ ├── download │ │ │ ├── DownloadJob.java │ │ │ ├── DownloadJobService.java │ │ │ └── FutureDownloadJob.java │ │ ├── processlst │ │ │ ├── FutureProcessListing.java │ │ │ ├── ProcessListing.java │ │ │ └── ProcessLstService.java │ │ ├── purge │ │ │ ├── FuturePurge.java │ │ │ ├── Purge.java │ │ │ └── PurgeService.java │ │ ├── submit │ │ │ ├── FutureSubmit.java │ │ │ ├── Submit.java │ │ │ └── SubmitService.java │ │ ├── tail │ │ │ ├── FutureTail.java │ │ │ ├── Tail.java │ │ │ └── TailService.java │ │ └── terminate │ │ │ └── TerminateService.java │ ├── localfile │ │ └── LocalFileService.java │ ├── memberlst │ │ ├── FutureMemberListing.java │ │ └── MemberListingService.java │ ├── omvs │ │ └── SshService.java │ ├── path │ │ └── PathService.java │ ├── rename │ │ ├── FutureRenameDataset.java │ │ ├── FutureRenameMember.java │ │ ├── RenameDataset.java │ │ ├── RenameMember.java │ │ └── RenameService.java │ ├── search │ │ ├── SearchCache.java │ │ └── SearchCacheService.java │ ├── tso │ │ ├── FutureTso.java │ │ ├── Tso.java │ │ └── TsoService.java │ ├── uname │ │ └── UnameService.java │ └── usermod │ │ └── UsermodService.java │ ├── singleton │ ├── CheckSumSingleton.java │ ├── ConnSingleton.java │ ├── EnvVariableSingleton.java │ ├── HistorySingleton.java │ ├── TerminalSingleton.java │ └── configuration │ │ ├── ConfigSingleton.java │ │ ├── model │ │ ├── Profile.java │ │ └── Window.java │ │ └── record │ │ └── ConfigSettings.java │ └── utility │ ├── DsnUtil.java │ ├── FileUtil.java │ ├── FutureUtil.java │ ├── PromptUtil.java │ ├── ResponseUtil.java │ └── StrUtil.java └── resources ├── image └── zowe-icon.png └── logback.xml /.github/workflows/maven-publish.yml: -------------------------------------------------------------------------------- 1 | # This workflow will build a package using Maven and then publish it to GitHub packages when a release is created 2 | # For more information see: https://github.com/actions/setup-java/blob/main/docs/advanced-usage.md#apache-maven-with-a-settings-path 3 | 4 | name: Maven Package 5 | 6 | on: 7 | release: 8 | types: [created] 9 | 10 | jobs: 11 | build: 12 | 13 | runs-on: ubuntu-latest 14 | permissions: 15 | contents: read 16 | packages: write 17 | 18 | steps: 19 | - uses: actions/checkout@v3 20 | - name: Set up JDK 11 21 | uses: actions/setup-java@v3 22 | with: 23 | java-version: '11' 24 | distribution: 'temurin' 25 | server-id: github # Value of the distributionManagement/repository/id field of the pom.xml 26 | settings-path: ${{ github.workspace }} # location for the settings.xml file 27 | 28 | - name: Build with Maven 29 | run: mvn -B package --file pom.xml 30 | 31 | - name: Publish to GitHub Packages Apache Maven 32 | run: mvn deploy -s $GITHUB_WORKSPACE/settings.xml 33 | env: 34 | GITHUB_TOKEN: ${{ github.token }} 35 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .idea/ 2 | *.log 3 | dependency-reduced-pom.xml 4 | target/ 5 | *.iml 6 | *.txt 7 | .classpath 8 | .factorypath 9 | .project 10 | .settings 11 | .swp 12 | zosshell-*.* 13 | zosshell-*.*.* 14 | .DS_Store -------------------------------------------------------------------------------- /demos/colors.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Zowe-Java-SDK/ZosShell/18d80f416b700725aaeb73e160f7562cae4939c4/demos/colors.gif -------------------------------------------------------------------------------- /demos/download-demo.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Zowe-Java-SDK/ZosShell/18d80f416b700725aaeb73e160f7562cae4939c4/demos/download-demo.gif -------------------------------------------------------------------------------- /demos/increase-size.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Zowe-Java-SDK/ZosShell/18d80f416b700725aaeb73e160f7562cae4939c4/demos/increase-size.gif -------------------------------------------------------------------------------- /demos/main-demo.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Zowe-Java-SDK/ZosShell/18d80f416b700725aaeb73e160f7562cae4939c4/demos/main-demo.gif -------------------------------------------------------------------------------- /demos/save-demo.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Zowe-Java-SDK/ZosShell/18d80f416b700725aaeb73e160f7562cae4939c4/demos/save-demo.gif -------------------------------------------------------------------------------- /src/main/java/zos/shell/controller/BrowseJobController.java: -------------------------------------------------------------------------------- 1 | package zos.shell.controller; 2 | 3 | import org.slf4j.Logger; 4 | import org.slf4j.LoggerFactory; 5 | import zos.shell.constants.Constants; 6 | import zos.shell.response.ResponseStatus; 7 | import zos.shell.service.job.browse.BrowseLogService; 8 | 9 | public class BrowseJobController { 10 | 11 | private static final Logger LOG = LoggerFactory.getLogger(BrowseJobController.class); 12 | 13 | private final BrowseLogService browseLogService; 14 | private final EnvVariableController envVariableController; 15 | 16 | public BrowseJobController(final BrowseLogService browseLogService, 17 | final EnvVariableController envVariableController) { 18 | LOG.debug("*** BrowseJobController ***"); 19 | this.browseLogService = browseLogService; 20 | this.envVariableController = envVariableController; 21 | } 22 | 23 | public String browseJob(final String target) { 24 | LOG.debug("*** browseJob ***"); 25 | ResponseStatus responseStatus = browseLogService.browseJob(target); 26 | String browseLimit = envVariableController.getValueByEnv("BROWSE_LIMIT").trim(); 27 | int browseLimitInt = 0; 28 | if (!browseLimit.isBlank()) { 29 | try { 30 | browseLimitInt = Integer.parseInt(browseLimit); 31 | } catch (NumberFormatException ignored) { 32 | } 33 | } 34 | if (responseStatus.getMessage().split("\\n").length > 35 | (browseLimitInt > 0 ? browseLimitInt : Constants.BROWSE_LIMIT)) { 36 | return Constants.BROWSE_LIMIT_WARNING; 37 | } 38 | return responseStatus.getMessage(); 39 | } 40 | 41 | } 42 | -------------------------------------------------------------------------------- /src/main/java/zos/shell/controller/CancelController.java: -------------------------------------------------------------------------------- 1 | package zos.shell.controller; 2 | 3 | import org.slf4j.Logger; 4 | import org.slf4j.LoggerFactory; 5 | import zos.shell.response.ResponseStatus; 6 | import zos.shell.service.job.terminate.TerminateService; 7 | import zos.shell.singleton.configuration.ConfigSingleton; 8 | 9 | public class CancelController { 10 | 11 | private static final Logger LOG = LoggerFactory.getLogger(CancelController.class); 12 | 13 | private final TerminateService terminateService; 14 | private final ConfigSingleton configSingleton; 15 | private final EnvVariableController envVariableController; 16 | 17 | public CancelController(final TerminateService terminateService, final ConfigSingleton configSingleton, 18 | final EnvVariableController envVariableController) { 19 | LOG.debug("*** CancelController ***"); 20 | this.terminateService = terminateService; 21 | this.configSingleton = configSingleton; 22 | this.envVariableController = envVariableController; 23 | } 24 | 25 | public String cancel(final String target) { 26 | LOG.debug("*** cancel ***"); 27 | String consoleName = envVariableController.getValueByEnv("CONSOLE_NAME").trim(); 28 | if (consoleName.isBlank()) { 29 | consoleName = configSingleton.getConfigSettings().getConsoleName(); 30 | } 31 | ResponseStatus responseStatus = terminateService.terminate(TerminateService.Type.CANCEL, consoleName, target); 32 | return responseStatus.getMessage(); 33 | } 34 | 35 | } 36 | -------------------------------------------------------------------------------- /src/main/java/zos/shell/controller/ChangeConnController.java: -------------------------------------------------------------------------------- 1 | package zos.shell.controller; 2 | 3 | import org.slf4j.Logger; 4 | import org.slf4j.LoggerFactory; 5 | import zos.shell.service.change.ChangeConnService; 6 | import zowe.client.sdk.core.SshConnection; 7 | import zowe.client.sdk.core.ZosConnection; 8 | 9 | public class ChangeConnController { 10 | 11 | private static final Logger LOG = LoggerFactory.getLogger(ChangeConnController.class); 12 | 13 | private final ChangeConnService changeConnService; 14 | 15 | public ChangeConnController(final ChangeConnService changeConnService) { 16 | LOG.debug("*** ChangeZosController ***"); 17 | this.changeConnService = changeConnService; 18 | } 19 | 20 | public ZosConnection changeZosConnection(final ZosConnection connection, final String[] commands) { 21 | LOG.debug("*** changeZosConnection ***"); 22 | return changeConnService.changeZosConnection(connection, commands); 23 | } 24 | 25 | public SshConnection changeSshConnection(final SshConnection connection, final String[] commands) { 26 | LOG.debug("*** changeSshConnection ***"); 27 | return changeConnService.changeSshConnection(connection, commands); 28 | } 29 | 30 | public void displayConnections() { 31 | LOG.debug("*** displayConnections ***"); 32 | changeConnService.displayConnections(); 33 | } 34 | 35 | } -------------------------------------------------------------------------------- /src/main/java/zos/shell/controller/ChangeDirController.java: -------------------------------------------------------------------------------- 1 | package zos.shell.controller; 2 | 3 | import org.slf4j.Logger; 4 | import org.slf4j.LoggerFactory; 5 | import zos.shell.response.ResponseStatus; 6 | import zos.shell.service.change.ChangeDirService; 7 | 8 | public class ChangeDirController { 9 | 10 | private static final Logger LOG = LoggerFactory.getLogger(ChangeDirController.class); 11 | 12 | private final ChangeDirService changeDirService; 13 | 14 | public ChangeDirController(final ChangeDirService changeDirService) { 15 | LOG.debug("*** ChangeDirController ***"); 16 | this.changeDirService = changeDirService; 17 | } 18 | 19 | public ResponseStatus cd(final String dataset, final String target) { 20 | LOG.debug("*** cd ***"); 21 | return changeDirService.cd(dataset, target); 22 | } 23 | 24 | } 25 | -------------------------------------------------------------------------------- /src/main/java/zos/shell/controller/ChangeWinController.java: -------------------------------------------------------------------------------- 1 | package zos.shell.controller; 2 | 3 | import org.slf4j.Logger; 4 | import org.slf4j.LoggerFactory; 5 | import zos.shell.service.change.ChangeWinService; 6 | 7 | public class ChangeWinController { 8 | 9 | private static final Logger LOG = LoggerFactory.getLogger(ChangeWinController.class); 10 | 11 | private final ChangeWinService changeWinService; 12 | 13 | public ChangeWinController(final ChangeWinService changeWinService) { 14 | LOG.debug("*** ChangeWinController ***"); 15 | this.changeWinService = changeWinService; 16 | } 17 | 18 | public String changeColorSettings(final String textColor, final String backGroundColor) { 19 | LOG.debug("*** changeColorSettings ***"); 20 | var str = new StringBuilder(); 21 | String result; 22 | result = changeWinService.setTextColor(textColor); 23 | str.append(result != null ? result + "\n" : ""); 24 | result = changeWinService.setBackGroundColor(backGroundColor); 25 | str.append(result != null ? result : ""); 26 | return str.toString(); 27 | } 28 | 29 | } 30 | -------------------------------------------------------------------------------- /src/main/java/zos/shell/controller/ConcatController.java: -------------------------------------------------------------------------------- 1 | package zos.shell.controller; 2 | 3 | import org.slf4j.Logger; 4 | import org.slf4j.LoggerFactory; 5 | import zos.shell.response.ResponseStatus; 6 | import zos.shell.service.dsn.concat.ConcatService; 7 | 8 | public class ConcatController { 9 | 10 | private static final Logger LOG = LoggerFactory.getLogger(ConcatController.class); 11 | 12 | private final ConcatService concatService; 13 | 14 | public ConcatController(final ConcatService concatService) { 15 | LOG.debug("*** ConCatController ***"); 16 | this.concatService = concatService; 17 | } 18 | 19 | public String cat(final String dataset, final String target) { 20 | LOG.debug("*** cat ***"); 21 | ResponseStatus responseStatus = concatService.cat(dataset, target); 22 | return responseStatus.getMessage(); 23 | } 24 | 25 | } 26 | -------------------------------------------------------------------------------- /src/main/java/zos/shell/controller/ConsoleController.java: -------------------------------------------------------------------------------- 1 | package zos.shell.controller; 2 | 3 | import org.slf4j.Logger; 4 | import org.slf4j.LoggerFactory; 5 | import zos.shell.response.ResponseStatus; 6 | import zos.shell.service.console.ConsoleService; 7 | import zos.shell.singleton.configuration.ConfigSingleton; 8 | 9 | public class ConsoleController { 10 | 11 | private static final Logger LOG = LoggerFactory.getLogger(ConsoleController.class); 12 | 13 | private final ConsoleService consoleService; 14 | private final ConfigSingleton configSingleton; 15 | private final EnvVariableController envVariableController; 16 | 17 | public ConsoleController(final ConsoleService consoleService, final ConfigSingleton configSingleton, 18 | final EnvVariableController envVariableController) { 19 | LOG.debug("*** ConsoleController ***"); 20 | this.consoleService = consoleService; 21 | this.configSingleton = configSingleton; 22 | this.envVariableController = envVariableController; 23 | } 24 | 25 | public String issueConsole(final String command) { 26 | LOG.debug("*** issueConsole ***"); 27 | String consoleName = envVariableController.getValueByEnv("CONSOLE_NAME").trim(); 28 | if (consoleName.isBlank()) { 29 | consoleName = configSingleton.getConfigSettings().getConsoleName(); 30 | } 31 | ResponseStatus responseStatus = consoleService.issueConsole(consoleName, command); 32 | return responseStatus.getMessage(); 33 | } 34 | 35 | } 36 | -------------------------------------------------------------------------------- /src/main/java/zos/shell/controller/CopyController.java: -------------------------------------------------------------------------------- 1 | package zos.shell.controller; 2 | 3 | import org.slf4j.Logger; 4 | import org.slf4j.LoggerFactory; 5 | import zos.shell.response.ResponseStatus; 6 | import zos.shell.service.dsn.copy.CopyService; 7 | 8 | public class CopyController { 9 | 10 | private static final Logger LOG = LoggerFactory.getLogger(CopyController.class); 11 | 12 | private final CopyService copyService; 13 | 14 | public CopyController(final CopyService copyService) { 15 | LOG.debug("*** CopyController ***"); 16 | this.copyService = copyService; 17 | } 18 | 19 | public String copy(final String dataset, final String[] params) { 20 | LOG.debug("*** copy ***"); 21 | ResponseStatus responseStatus = copyService.copy(dataset, params); 22 | return responseStatus.getMessage(); 23 | } 24 | 25 | } 26 | -------------------------------------------------------------------------------- /src/main/java/zos/shell/controller/CountController.java: -------------------------------------------------------------------------------- 1 | package zos.shell.controller; 2 | 3 | import org.slf4j.Logger; 4 | import org.slf4j.LoggerFactory; 5 | import zos.shell.response.ResponseStatus; 6 | import zos.shell.service.dsn.count.CountService; 7 | 8 | public class CountController { 9 | 10 | private static final Logger LOG = LoggerFactory.getLogger(CountController.class); 11 | 12 | private final CountService countService; 13 | 14 | public CountController(final CountService countService) { 15 | LOG.debug("*** CountController ***"); 16 | this.countService = countService; 17 | } 18 | 19 | public String count(final String dataset, final String filter) { 20 | LOG.debug("*** count ***"); 21 | ResponseStatus responseStatus = countService.count(dataset, filter); 22 | return responseStatus.getMessage(); 23 | } 24 | 25 | } 26 | -------------------------------------------------------------------------------- /src/main/java/zos/shell/controller/DeleteController.java: -------------------------------------------------------------------------------- 1 | package zos.shell.controller; 2 | 3 | import org.slf4j.Logger; 4 | import org.slf4j.LoggerFactory; 5 | import zos.shell.response.ResponseStatus; 6 | import zos.shell.service.dsn.delete.DeleteService; 7 | 8 | public class DeleteController { 9 | 10 | private static final Logger LOG = LoggerFactory.getLogger(DeleteController.class); 11 | 12 | private final DeleteService deleteService; 13 | 14 | public DeleteController(final DeleteService deleteService) { 15 | LOG.debug("*** DeleteController ***"); 16 | this.deleteService = deleteService; 17 | } 18 | 19 | public String rm(final String dataset, final String param) { 20 | LOG.debug("*** rm ***"); 21 | ResponseStatus responseStatus = deleteService.delete(dataset, param); 22 | return responseStatus.getMessage(); 23 | } 24 | 25 | } 26 | -------------------------------------------------------------------------------- /src/main/java/zos/shell/controller/DownloadJobController.java: -------------------------------------------------------------------------------- 1 | package zos.shell.controller; 2 | 3 | import org.slf4j.Logger; 4 | import org.slf4j.LoggerFactory; 5 | import zos.shell.response.ResponseStatus; 6 | import zos.shell.service.job.download.DownloadJobService; 7 | 8 | public class DownloadJobController { 9 | 10 | private static final Logger LOG = LoggerFactory.getLogger(DownloadJobController.class); 11 | 12 | private final DownloadJobService downloadJobService; 13 | 14 | public DownloadJobController(final DownloadJobService downloadJobService) { 15 | LOG.debug("*** DownloadJobController ***"); 16 | this.downloadJobService = downloadJobService; 17 | } 18 | 19 | public String downloadJob(final String target) { 20 | LOG.debug("*** downloadJob ***"); 21 | ResponseStatus responseStatus = downloadJobService.download(target); 22 | return responseStatus.getMessage(); 23 | } 24 | 25 | } 26 | -------------------------------------------------------------------------------- /src/main/java/zos/shell/controller/EchoController.java: -------------------------------------------------------------------------------- 1 | package zos.shell.controller; 2 | 3 | import org.slf4j.Logger; 4 | import org.slf4j.LoggerFactory; 5 | import zos.shell.service.echo.EchoService; 6 | 7 | public class EchoController { 8 | 9 | private static final Logger LOG = LoggerFactory.getLogger(EchoController.class); 10 | 11 | private final EchoService echoService; 12 | 13 | public EchoController(final EchoService echoService) { 14 | LOG.debug("*** EchoController ***"); 15 | this.echoService = echoService; 16 | } 17 | 18 | public String getEcho(final String arg) { 19 | LOG.debug("*** getEcho ***"); 20 | return echoService.getEcho(arg); 21 | } 22 | 23 | } 24 | -------------------------------------------------------------------------------- /src/main/java/zos/shell/controller/EditController.java: -------------------------------------------------------------------------------- 1 | package zos.shell.controller; 2 | 3 | import org.slf4j.Logger; 4 | import org.slf4j.LoggerFactory; 5 | import zos.shell.response.ResponseStatus; 6 | import zos.shell.service.dsn.edit.EditService; 7 | 8 | public class EditController { 9 | 10 | private static final Logger LOG = LoggerFactory.getLogger(EditController.class); 11 | 12 | private final EditService editService; 13 | 14 | public EditController(final EditService editService) { 15 | LOG.debug("*** EditController ***"); 16 | this.editService = editService; 17 | } 18 | 19 | public String edit(final String dataset, final String target) { 20 | LOG.debug("*** edit ***"); 21 | ResponseStatus responseStatus = editService.open(dataset, target); 22 | return responseStatus.getMessage(); 23 | } 24 | 25 | } 26 | -------------------------------------------------------------------------------- /src/main/java/zos/shell/controller/EnvVariableController.java: -------------------------------------------------------------------------------- 1 | package zos.shell.controller; 2 | 3 | import org.slf4j.Logger; 4 | import org.slf4j.LoggerFactory; 5 | import zos.shell.constants.Constants; 6 | import zos.shell.service.env.EnvVariableService; 7 | import zos.shell.utility.StrUtil; 8 | 9 | import java.util.TreeMap; 10 | 11 | public class EnvVariableController { 12 | 13 | private static final Logger LOG = LoggerFactory.getLogger(EnvVariableController.class); 14 | 15 | private final EnvVariableService envVariableService; 16 | 17 | public EnvVariableController(final EnvVariableService envVariableService) { 18 | LOG.debug("*** EnvVariableController ***"); 19 | this.envVariableService = envVariableService; 20 | } 21 | 22 | public String env() { 23 | LOG.debug("*** env ***"); 24 | if (envVariableService.getEnvVariables().isEmpty()) { 25 | return "no environment variables set, try again..."; 26 | } 27 | var str = new StringBuilder(); 28 | new TreeMap<>(envVariableService.getEnvVariables()) 29 | .forEach((k, v) -> str.append(k).append("=").append(v).append("\n")); 30 | return str.toString(); 31 | } 32 | 33 | public String set(final String key_value) { 34 | LOG.debug("*** set ***"); 35 | var values = key_value.split("="); 36 | if (values.length != 2) { 37 | return Constants.INVALID_COMMAND; 38 | } 39 | envVariableService.setEnvVariable(values[0].trim(), values[1].trim()); 40 | if (values[0].equalsIgnoreCase("acctnum")) { 41 | if (!StrUtil.isStrNum(values[1])) { 42 | return "ACCTNUM value not a number, try again..."; 43 | } 44 | } 45 | return values[0] + "=" + values[1]; 46 | } 47 | 48 | public String getValueByEnv(final String key) { 49 | LOG.debug("*** getValueByEnv ***"); 50 | return envVariableService.getValueByEnvName(key); 51 | } 52 | 53 | } 54 | -------------------------------------------------------------------------------- /src/main/java/zos/shell/controller/GrepController.java: -------------------------------------------------------------------------------- 1 | package zos.shell.controller; 2 | 3 | import org.slf4j.Logger; 4 | import org.slf4j.LoggerFactory; 5 | import zos.shell.service.grep.GrepService; 6 | 7 | public class GrepController { 8 | 9 | private static final Logger LOG = LoggerFactory.getLogger(GrepController.class); 10 | 11 | private final GrepService grepService; 12 | 13 | public GrepController(final GrepService grepService) { 14 | LOG.debug("*** GrepController ***"); 15 | this.grepService = grepService; 16 | } 17 | 18 | public String grep(final String target, final String dataset) { 19 | LOG.debug("*** grep ***"); 20 | var results = new StringBuilder(); 21 | grepService.search(dataset, target).forEach(i -> { 22 | if (i.endsWith("\n")) { 23 | results.append(i); 24 | } else { 25 | results.append(i).append("\n"); 26 | } 27 | }); 28 | return results.toString(); 29 | } 30 | 31 | } 32 | -------------------------------------------------------------------------------- /src/main/java/zos/shell/controller/ListingController.java: -------------------------------------------------------------------------------- 1 | package zos.shell.controller; 2 | 3 | import org.slf4j.Logger; 4 | import org.slf4j.LoggerFactory; 5 | import zos.shell.response.ResponseStatus; 6 | import zos.shell.service.dsn.list.ListingService; 7 | import zos.shell.utility.ResponseUtil; 8 | import zowe.client.sdk.rest.exception.ZosmfRequestException; 9 | 10 | public class ListingController { 11 | 12 | private static final Logger LOG = LoggerFactory.getLogger(ListingController.class); 13 | 14 | private final ListingService listingService; 15 | 16 | public ListingController(final ListingService listingService) { 17 | LOG.debug("*** ListingController ***"); 18 | this.listingService = listingService; 19 | } 20 | 21 | public ResponseStatus ls(final String member, final String dataset) { 22 | LOG.debug("*** ls 1 ***"); 23 | try { 24 | listingService.ls(member, dataset, true, false); 25 | } catch (ZosmfRequestException e) { 26 | var errMsg = ResponseUtil.getResponsePhrase(e.getResponse()); 27 | return new ResponseStatus(errMsg != null ? errMsg : e.getMessage(), false); 28 | } 29 | return new ResponseStatus("success", true); 30 | } 31 | 32 | public ResponseStatus ls(final String dataset) { 33 | LOG.debug("*** ls 2 ***"); 34 | try { 35 | listingService.ls(null, dataset, true, false); 36 | } catch (ZosmfRequestException e) { 37 | var errMsg = ResponseUtil.getResponsePhrase(e.getResponse()); 38 | return new ResponseStatus(errMsg != null ? errMsg : e.getMessage(), false); 39 | } 40 | return new ResponseStatus("success", true); 41 | } 42 | 43 | public ResponseStatus lsl(final String dataset, final boolean isAttributes) { 44 | LOG.debug("*** lsl 1 ***"); 45 | return this.lsl(null, dataset, isAttributes); 46 | } 47 | 48 | public ResponseStatus lsl(final String member, final String dataset, final boolean isAttributes) { 49 | LOG.debug("*** lsl 2 ***"); 50 | try { 51 | listingService.ls(member, dataset, false, isAttributes); 52 | } catch (ZosmfRequestException e) { 53 | var errMsg = ResponseUtil.getResponsePhrase(e.getResponse()); 54 | return new ResponseStatus(errMsg != null ? errMsg : e.getMessage(), false); 55 | } 56 | return new ResponseStatus("success", true); 57 | } 58 | 59 | } 60 | -------------------------------------------------------------------------------- /src/main/java/zos/shell/controller/LocalFilesController.java: -------------------------------------------------------------------------------- 1 | package zos.shell.controller; 2 | 3 | import org.slf4j.Logger; 4 | import org.slf4j.LoggerFactory; 5 | import zos.shell.service.localfile.LocalFileService; 6 | 7 | public class LocalFilesController { 8 | 9 | private static final Logger LOG = LoggerFactory.getLogger(LocalFilesController.class); 10 | 11 | private final LocalFileService localFileService; 12 | 13 | public LocalFilesController(final LocalFileService localFileService) { 14 | LOG.debug("*** LocalFilesController ***"); 15 | this.localFileService = localFileService; 16 | } 17 | 18 | public StringBuilder files(String dataset) { 19 | LOG.debug("*** files ***"); 20 | return localFileService.listFiles(dataset); 21 | } 22 | 23 | } 24 | -------------------------------------------------------------------------------- /src/main/java/zos/shell/controller/ProcessLstController.java: -------------------------------------------------------------------------------- 1 | package zos.shell.controller; 2 | 3 | import org.slf4j.Logger; 4 | import org.slf4j.LoggerFactory; 5 | import zos.shell.response.ResponseStatus; 6 | import zos.shell.service.job.processlst.ProcessLstService; 7 | 8 | public class ProcessLstController { 9 | 10 | private static final Logger LOG = LoggerFactory.getLogger(ProcessLstController.class); 11 | 12 | private final ProcessLstService processListingService; 13 | 14 | public ProcessLstController(final ProcessLstService processListingService) { 15 | this.processListingService = processListingService; 16 | } 17 | 18 | public String processList() { 19 | LOG.debug("*** processList all ***"); 20 | return processList(null); 21 | } 22 | 23 | public String processList(final String target) { 24 | LOG.debug("*** processList target ***"); 25 | ResponseStatus responseStatus = processListingService.processLst(target); 26 | return responseStatus.getMessage(); 27 | } 28 | 29 | } 30 | -------------------------------------------------------------------------------- /src/main/java/zos/shell/controller/PurgeController.java: -------------------------------------------------------------------------------- 1 | package zos.shell.controller; 2 | 3 | import org.slf4j.Logger; 4 | import org.slf4j.LoggerFactory; 5 | import zos.shell.response.ResponseStatus; 6 | import zos.shell.service.job.purge.PurgeService; 7 | 8 | public class PurgeController { 9 | 10 | private static final Logger LOG = LoggerFactory.getLogger(PurgeController.class); 11 | 12 | private final PurgeService purgeService; 13 | 14 | public PurgeController(final PurgeService purgeService) { 15 | this.purgeService = purgeService; 16 | } 17 | 18 | public String purge(final String filter) { 19 | LOG.debug("*** purge ***"); 20 | ResponseStatus responseStatus = purgeService.purge(filter); 21 | return responseStatus.getMessage(); 22 | } 23 | 24 | } 25 | -------------------------------------------------------------------------------- /src/main/java/zos/shell/controller/RenameController.java: -------------------------------------------------------------------------------- 1 | package zos.shell.controller; 2 | 3 | import org.slf4j.Logger; 4 | import org.slf4j.LoggerFactory; 5 | import zos.shell.response.ResponseStatus; 6 | import zos.shell.service.rename.RenameService; 7 | 8 | public class RenameController { 9 | 10 | private static final Logger LOG = LoggerFactory.getLogger(RenameController.class); 11 | 12 | private final RenameService renameService; 13 | 14 | public RenameController(final RenameService renameService) { 15 | LOG.debug("*** RenameController ***"); 16 | this.renameService = renameService; 17 | } 18 | 19 | public String rename(final String dataset, final String target, final String source) { 20 | LOG.debug("*** rename ***"); 21 | ResponseStatus responseStatus = renameService.rename(dataset, target, source); 22 | return responseStatus.getMessage(); 23 | } 24 | 25 | } 26 | -------------------------------------------------------------------------------- /src/main/java/zos/shell/controller/SaveController.java: -------------------------------------------------------------------------------- 1 | package zos.shell.controller; 2 | 3 | import org.slf4j.Logger; 4 | import org.slf4j.LoggerFactory; 5 | import zos.shell.response.ResponseStatus; 6 | import zos.shell.service.dsn.save.SaveService; 7 | 8 | public class SaveController { 9 | 10 | private static final Logger LOG = LoggerFactory.getLogger(SaveController.class); 11 | 12 | private final SaveService saveService; 13 | 14 | public SaveController(final SaveService saveService) { 15 | LOG.debug("*** SaveController ***"); 16 | this.saveService = saveService; 17 | } 18 | 19 | public String save(final String dataset, final String target) { 20 | LOG.debug("*** save ***"); 21 | ResponseStatus responseStatus = saveService.save(dataset, target); 22 | return responseStatus.getMessage(); 23 | } 24 | 25 | } 26 | -------------------------------------------------------------------------------- /src/main/java/zos/shell/controller/SearchCacheController.java: -------------------------------------------------------------------------------- 1 | package zos.shell.controller; 2 | 3 | import org.slf4j.Logger; 4 | import org.slf4j.LoggerFactory; 5 | import zos.shell.service.search.SearchCache; 6 | import zos.shell.service.search.SearchCacheService; 7 | 8 | import java.util.List; 9 | 10 | public class SearchCacheController { 11 | 12 | private static final Logger LOG = LoggerFactory.getLogger(SearchCacheController.class); 13 | 14 | private final SearchCacheService searchCacheService; 15 | 16 | public SearchCacheController(final SearchCacheService searchCacheService) { 17 | LOG.debug("*** SearchCacheController ***"); 18 | this.searchCacheService = searchCacheService; 19 | } 20 | 21 | public List search(final SearchCache output, final String text) { 22 | LOG.debug("*** search ***"); 23 | return searchCacheService.search(output, text); 24 | } 25 | 26 | } 27 | -------------------------------------------------------------------------------- /src/main/java/zos/shell/controller/StopController.java: -------------------------------------------------------------------------------- 1 | package zos.shell.controller; 2 | 3 | import org.slf4j.Logger; 4 | import org.slf4j.LoggerFactory; 5 | import zos.shell.response.ResponseStatus; 6 | import zos.shell.service.job.terminate.TerminateService; 7 | import zos.shell.singleton.configuration.ConfigSingleton; 8 | 9 | public class StopController { 10 | 11 | private static final Logger LOG = LoggerFactory.getLogger(StopController.class); 12 | 13 | private final TerminateService terminateService; 14 | private final ConfigSingleton configSingleton; 15 | private final EnvVariableController envVariableController; 16 | 17 | public StopController(final TerminateService terminateService, final ConfigSingleton configSingleton, 18 | final EnvVariableController envVariableController) { 19 | LOG.debug("*** TerminateController ***"); 20 | this.terminateService = terminateService; 21 | this.configSingleton = configSingleton; 22 | this.envVariableController = envVariableController; 23 | } 24 | 25 | public String stop(final String target) { 26 | LOG.debug("*** stop ***"); 27 | String consoleName = envVariableController.getValueByEnv("CONSOLE_NAME").trim(); 28 | if (consoleName.isBlank()) { 29 | consoleName = configSingleton.getConfigSettings().getConsoleName(); 30 | } 31 | ResponseStatus responseStatus = terminateService.terminate(TerminateService.Type.STOP, consoleName, target); 32 | return responseStatus.getMessage(); 33 | } 34 | 35 | } 36 | -------------------------------------------------------------------------------- /src/main/java/zos/shell/controller/SubmitController.java: -------------------------------------------------------------------------------- 1 | package zos.shell.controller; 2 | 3 | import org.slf4j.Logger; 4 | import org.slf4j.LoggerFactory; 5 | import zos.shell.response.ResponseStatus; 6 | import zos.shell.service.job.submit.SubmitService; 7 | 8 | public class SubmitController { 9 | 10 | private static final Logger LOG = LoggerFactory.getLogger(SubmitController.class); 11 | 12 | private final SubmitService submitService; 13 | 14 | public SubmitController(final SubmitService submitService) { 15 | LOG.debug("*** SubmitController ***"); 16 | this.submitService = submitService; 17 | } 18 | 19 | public String submit(final String dataset, final String target) { 20 | LOG.debug("*** submit ***"); 21 | ResponseStatus responseStatus = submitService.submit(dataset, target); 22 | return responseStatus.getMessage(); 23 | } 24 | 25 | } 26 | -------------------------------------------------------------------------------- /src/main/java/zos/shell/controller/TailController.java: -------------------------------------------------------------------------------- 1 | package zos.shell.controller; 2 | 3 | import org.slf4j.Logger; 4 | import org.slf4j.LoggerFactory; 5 | import zos.shell.response.ResponseStatus; 6 | import zos.shell.service.job.tail.TailService; 7 | import zos.shell.service.search.SearchCache; 8 | 9 | import java.util.Arrays; 10 | 11 | public class TailController { 12 | 13 | private static final Logger LOG = LoggerFactory.getLogger(TailController.class); 14 | 15 | private final TailService tailService; 16 | 17 | public TailController(final TailService tailService) { 18 | LOG.debug("*** TailController ***"); 19 | this.tailService = tailService; 20 | } 21 | 22 | public SearchCache tail(final String[] params) { 23 | LOG.debug("*** tail ***"); 24 | long allCount = Arrays.stream(params).filter("ALL"::equalsIgnoreCase).count(); 25 | ResponseStatus responseStatus = tailService.tail(params, allCount == 1); 26 | return new SearchCache("tail", new StringBuilder(responseStatus.getMessage())); 27 | } 28 | 29 | } 30 | -------------------------------------------------------------------------------- /src/main/java/zos/shell/controller/TouchController.java: -------------------------------------------------------------------------------- 1 | package zos.shell.controller; 2 | 3 | import org.slf4j.Logger; 4 | import org.slf4j.LoggerFactory; 5 | import zos.shell.response.ResponseStatus; 6 | import zos.shell.service.dsn.touch.TouchService; 7 | 8 | public class TouchController { 9 | 10 | private static final Logger LOG = LoggerFactory.getLogger(TouchController.class); 11 | 12 | private final TouchService touchService; 13 | 14 | public TouchController(final TouchService touchService) { 15 | LOG.debug("*** TouchController ***"); 16 | this.touchService = touchService; 17 | } 18 | 19 | public String touch(final String dataset, final String target) { 20 | LOG.debug("*** touch ***"); 21 | ResponseStatus responseStatus = touchService.touch(dataset, target); 22 | return responseStatus.getMessage(); 23 | } 24 | 25 | } 26 | -------------------------------------------------------------------------------- /src/main/java/zos/shell/controller/TsoController.java: -------------------------------------------------------------------------------- 1 | package zos.shell.controller; 2 | 3 | import org.slf4j.Logger; 4 | import org.slf4j.LoggerFactory; 5 | import zos.shell.response.ResponseStatus; 6 | import zos.shell.service.tso.TsoService; 7 | import zos.shell.singleton.configuration.ConfigSingleton; 8 | 9 | public class TsoController { 10 | 11 | private static final Logger LOG = LoggerFactory.getLogger(TsoController.class); 12 | 13 | private final TsoService tsoService; 14 | private final ConfigSingleton configSingleton; 15 | private final EnvVariableController envVariableController; 16 | 17 | public TsoController(final TsoService tsoService, final ConfigSingleton configSingleton, 18 | final EnvVariableController envVariableController) { 19 | LOG.debug("*** TsoController ***"); 20 | this.tsoService = tsoService; 21 | this.configSingleton = configSingleton; 22 | this.envVariableController = envVariableController; 23 | } 24 | 25 | public String issueCommand(final String command) { 26 | LOG.debug("*** issueCommand ***"); 27 | String accountNumber = envVariableController.getValueByEnv("ACCOUNT_NUMBER").trim(); 28 | if (accountNumber.isBlank()) { 29 | accountNumber = configSingleton.getConfigSettings().getAccountNumber(); 30 | } 31 | ResponseStatus responseStatus = tsoService.issueCommand(accountNumber, command); 32 | return responseStatus.getMessage(); 33 | } 34 | 35 | } 36 | -------------------------------------------------------------------------------- /src/main/java/zos/shell/controller/UnameController.java: -------------------------------------------------------------------------------- 1 | package zos.shell.controller; 2 | 3 | import org.slf4j.Logger; 4 | import org.slf4j.LoggerFactory; 5 | import zos.shell.service.uname.UnameService; 6 | import zos.shell.singleton.configuration.ConfigSingleton; 7 | import zowe.client.sdk.core.ZosConnection; 8 | 9 | public class UnameController { 10 | 11 | private static final Logger LOG = LoggerFactory.getLogger(UnameController.class); 12 | 13 | private final UnameService unameService; 14 | private final ConfigSingleton configSingleton; 15 | private final EnvVariableController envVariableController; 16 | 17 | public UnameController(final UnameService unameService, final ConfigSingleton configSingleton, 18 | final EnvVariableController envVariableController) { 19 | LOG.debug("*** UnameController ***"); 20 | this.unameService = unameService; 21 | this.configSingleton = configSingleton; 22 | this.envVariableController = envVariableController; 23 | } 24 | 25 | public String uname(final ZosConnection connection) { 26 | LOG.debug("*** uname ***"); 27 | String consoleName = envVariableController.getValueByEnv("CONSOLE_NAME").trim(); 28 | if (consoleName.isBlank()) { 29 | consoleName = configSingleton.getConfigSettings().getConsoleName(); 30 | } 31 | return unameService.getUname(connection.getHost(), consoleName); 32 | } 33 | 34 | } 35 | -------------------------------------------------------------------------------- /src/main/java/zos/shell/controller/UsermodController.java: -------------------------------------------------------------------------------- 1 | package zos.shell.controller; 2 | 3 | import org.slf4j.Logger; 4 | import org.slf4j.LoggerFactory; 5 | import zos.shell.constants.Constants; 6 | import zos.shell.service.usermod.UsermodService; 7 | 8 | public class UsermodController { 9 | 10 | private static final Logger LOG = LoggerFactory.getLogger(UsermodController.class); 11 | 12 | private final UsermodService usermodService; 13 | 14 | public UsermodController(final UsermodService usermodService) { 15 | LOG.debug("*** UsermodController ***"); 16 | this.usermodService = usermodService; 17 | } 18 | 19 | public String change(final String flag) { 20 | LOG.debug("*** change ***"); 21 | if ("-u".equalsIgnoreCase(flag)) { 22 | return usermodService.changeUsername(); 23 | } 24 | if ("-p".equalsIgnoreCase(flag)) { 25 | return usermodService.changePassword(); 26 | } else { 27 | return Constants.INVALID_COMMAND; 28 | } 29 | } 30 | 31 | } 32 | -------------------------------------------------------------------------------- /src/main/java/zos/shell/controller/UssController.java: -------------------------------------------------------------------------------- 1 | package zos.shell.controller; 2 | 3 | import org.slf4j.Logger; 4 | import org.slf4j.LoggerFactory; 5 | import zos.shell.service.omvs.SshService; 6 | 7 | public class UssController { 8 | 9 | private static final Logger LOG = LoggerFactory.getLogger(UssController.class); 10 | 11 | private final SshService sshService; 12 | 13 | public UssController(final SshService sshService) { 14 | LOG.debug("*** UssController ***"); 15 | this.sshService = sshService; 16 | } 17 | 18 | public String issueUnixCommand(final String command) { 19 | LOG.debug("*** issueUnixCommand ***"); 20 | return sshService.sshCommand(command); 21 | } 22 | 23 | } 24 | -------------------------------------------------------------------------------- /src/main/java/zos/shell/controller/container/ContainerType.java: -------------------------------------------------------------------------------- 1 | package zos.shell.controller.container; 2 | 3 | public class ContainerType { 4 | 5 | public enum Name { 6 | BROWSE_JOB, 7 | CANCEL, 8 | CHANGE_CONNECTION, 9 | CHANGE_DIRECTORY, 10 | CHANGE_WINDOW, 11 | CONCAT, 12 | CONSOLE, 13 | COPY, 14 | COUNT, 15 | DELETE, 16 | DOWNLOAD_JOB, 17 | ECHO, 18 | EDIT, 19 | GREP, 20 | LIST, 21 | LOCAL_FILE, 22 | MAKE_DIR, 23 | PROCESS_LIST, 24 | PURGE, 25 | RENAME, 26 | SAVE, 27 | SEARCH_CACHE, 28 | STOP, 29 | SUBMIT, 30 | TAIL, 31 | TOUCH, 32 | TSO, 33 | UNAME, 34 | USERMOD, 35 | USS 36 | } 37 | 38 | } 39 | -------------------------------------------------------------------------------- /src/main/java/zos/shell/controller/container/Dependency.java: -------------------------------------------------------------------------------- 1 | package zos.shell.controller.container; 2 | 3 | import org.slf4j.Logger; 4 | import org.slf4j.LoggerFactory; 5 | import zowe.client.sdk.core.SshConnection; 6 | import zowe.client.sdk.core.ZosConnection; 7 | 8 | import java.util.Objects; 9 | import java.util.Optional; 10 | import java.util.OptionalLong; 11 | 12 | public class Dependency { 13 | 14 | private static final Logger LOG = LoggerFactory.getLogger(Dependency.class); 15 | 16 | private final Optional zosConnection; 17 | private final Optional sshConnection; 18 | private final Optional data; 19 | private final boolean toggle; 20 | private final OptionalLong timeout; 21 | 22 | public Dependency(Builder builder) { 23 | LOG.debug("*** Dependency ***"); 24 | this.zosConnection = Optional.ofNullable(builder.zosConnection); 25 | this.sshConnection = Optional.ofNullable(builder.sshConnection); 26 | if (builder.data == null) { 27 | this.data = Optional.empty(); 28 | } else { 29 | this.data = Optional.of(builder.data); 30 | } 31 | if (builder.timeout == 0) { 32 | this.timeout = OptionalLong.empty(); 33 | } else { 34 | this.timeout = OptionalLong.of(builder.timeout); 35 | } 36 | this.toggle = builder.toggle; 37 | } 38 | 39 | @Override 40 | public boolean equals(Object o) { 41 | LOG.debug("*** equals ***"); 42 | if (o == null || getClass() != o.getClass()) return false; 43 | Dependency that = (Dependency) o; 44 | return toggle == that.toggle && Objects.equals(zosConnection, that.zosConnection) && 45 | Objects.equals(sshConnection, that.sshConnection) && Objects.equals(data, that.data) && 46 | Objects.equals(timeout, that.timeout); 47 | } 48 | 49 | @Override 50 | public int hashCode() { 51 | LOG.debug("*** hashCode ***"); 52 | return Objects.hash(zosConnection, sshConnection, data, toggle, timeout); 53 | } 54 | 55 | public static class Builder { 56 | 57 | private ZosConnection zosConnection; 58 | private SshConnection sshConnection; 59 | private String data; 60 | private boolean toggle; 61 | private long timeout; 62 | 63 | public Builder zosConnection(final ZosConnection zosConnection) { 64 | this.zosConnection = zosConnection; 65 | return this; 66 | } 67 | 68 | public Builder sshConnection(final SshConnection sshConnection) { 69 | this.sshConnection = sshConnection; 70 | return this; 71 | } 72 | 73 | public Builder data(final String data) { 74 | this.data = data; 75 | return this; 76 | } 77 | 78 | public Builder toggle(final boolean toggle) { 79 | this.toggle = toggle; 80 | return this; 81 | } 82 | 83 | public Builder timeout(final long timeout) { 84 | this.timeout = timeout; 85 | return this; 86 | } 87 | 88 | public Dependency build() { 89 | return new Dependency(this); 90 | } 91 | 92 | } 93 | 94 | } 95 | -------------------------------------------------------------------------------- /src/main/java/zos/shell/record/DatasetMember.java: -------------------------------------------------------------------------------- 1 | package zos.shell.record; 2 | 3 | import org.slf4j.Logger; 4 | import org.slf4j.LoggerFactory; 5 | import zos.shell.utility.DsnUtil; 6 | 7 | public class DatasetMember { 8 | 9 | private static final Logger LOG = LoggerFactory.getLogger(DatasetMember.class); 10 | 11 | private final String dataset; 12 | private final String member; 13 | 14 | public DatasetMember(final String dataset, final String member) { 15 | LOG.debug("*** DatasetMember ***"); 16 | this.dataset = dataset; 17 | this.member = member; 18 | } 19 | 20 | public String getDataset() { 21 | LOG.debug("*** getDataset ***"); 22 | return dataset; 23 | } 24 | 25 | public String getMember() { 26 | LOG.debug("*** getMember ***"); 27 | return member; 28 | } 29 | 30 | public static DatasetMember getDatasetAndMember(final String target) { 31 | LOG.debug("*** getMemberFromDataSet ***"); 32 | int index = target.indexOf("("); 33 | if (index == -1) { 34 | return null; 35 | } 36 | var dataset = target.substring(0, index); 37 | if (!DsnUtil.isDataset(dataset)) { 38 | return null; 39 | } 40 | 41 | var member = target.substring(index + 1, target.length() - 1); 42 | if (!DsnUtil.isMember(member)) { 43 | return null; 44 | } 45 | return new DatasetMember(dataset, member); 46 | } 47 | 48 | @Override 49 | public String toString() { 50 | return "DataSetMember{" + 51 | "dataSet='" + dataset + '\'' + 52 | ", member='" + member + '\'' + 53 | '}'; 54 | } 55 | 56 | } 57 | -------------------------------------------------------------------------------- /src/main/java/zos/shell/response/ResponseStatus.java: -------------------------------------------------------------------------------- 1 | package zos.shell.response; 2 | 3 | public class ResponseStatus { 4 | 5 | private String message; 6 | private final boolean status; 7 | private String optionalData; 8 | 9 | public ResponseStatus(final String message, final boolean status) { 10 | this.message = message; 11 | this.status = status; 12 | } 13 | 14 | public ResponseStatus(final String message, final boolean status, final String optionalData) { 15 | this.message = message; 16 | this.status = status; 17 | this.optionalData = optionalData; 18 | } 19 | 20 | public String getMessage() { 21 | return message; 22 | } 23 | 24 | public void setMessage(final String message) { 25 | this.message = message; 26 | } 27 | 28 | public boolean isStatus() { 29 | return status; 30 | } 31 | 32 | public String getOptionalData() { 33 | return optionalData; 34 | } 35 | 36 | @Override 37 | public String toString() { 38 | return "ResponseStatus{" + 39 | "message='" + message + '\'' + 40 | ", status=" + status + 41 | ", optionalData='" + optionalData + '\'' + 42 | '}'; 43 | } 44 | 45 | } 46 | -------------------------------------------------------------------------------- /src/main/java/zos/shell/service/autocomplete/SearchCommandService.java: -------------------------------------------------------------------------------- 1 | package zos.shell.service.autocomplete; 2 | 3 | import org.slf4j.Logger; 4 | import org.slf4j.LoggerFactory; 5 | 6 | import java.util.List; 7 | 8 | public final class SearchCommandService { 9 | 10 | private static final Logger LOG = LoggerFactory.getLogger(SearchCommandService.class); 11 | 12 | private static final String[] commands = new String[]{"browsejob", "cancel", "cat", "cd", "change", "clear", 13 | "color", "connections", "count", "copy", "download", "downloadjob", "end", "env", "files", "grep", 14 | "help", "history", "hostname", "ls", "mkdir", "mvs", "purge", "ps", "pwd", "rename", "rm", "rn", "save", 15 | "search", "set", "stop", "submit", "tail", "timeout", "touch", "tso", "uname", "usermod", "ussh", "vi", 16 | "visited", "whoami"}; 17 | 18 | private final TriePreFix dictionary = new TriePreFix(commands); 19 | 20 | public SearchCommandService() { 21 | LOG.debug("*** SearchCommandService ***"); 22 | } 23 | 24 | public List search(String prefix) { 25 | LOG.debug("*** search command for autofill ***"); 26 | return dictionary.getCommands(prefix); 27 | } 28 | 29 | } 30 | -------------------------------------------------------------------------------- /src/main/java/zos/shell/service/autocomplete/TriePreFix.java: -------------------------------------------------------------------------------- 1 | package zos.shell.service.autocomplete; 2 | 3 | import java.util.ArrayList; 4 | import java.util.List; 5 | 6 | public class TriePreFix { 7 | 8 | private final TrieNode root; 9 | 10 | public TriePreFix(String[] commands) { 11 | root = new TrieNode(); 12 | root.addCommands(commands); 13 | } 14 | 15 | public List getCommands(String prefix) { 16 | var lastNode = root; 17 | int limit = prefix.length(); 18 | 19 | // retrieve the last Node of the trie for 20 | // the last character of the prefix 21 | for (var i = 0; i < limit; i++) { 22 | lastNode = lastNode.getNode(prefix.charAt(i) - 'a'); 23 | // if none, return an empty array 24 | if (lastNode == null) { 25 | return new ArrayList<>(); 26 | } 27 | } 28 | 29 | return lastNode.getCommands(); 30 | } 31 | 32 | } 33 | -------------------------------------------------------------------------------- /src/main/java/zos/shell/service/change/ChangeDirService.java: -------------------------------------------------------------------------------- 1 | package zos.shell.service.change; 2 | 3 | import org.slf4j.Logger; 4 | import org.slf4j.LoggerFactory; 5 | import zos.shell.constants.Constants; 6 | import zos.shell.response.ResponseStatus; 7 | import zos.shell.utility.DsnUtil; 8 | 9 | public class ChangeDirService { 10 | 11 | private static final Logger LOG = LoggerFactory.getLogger(ChangeDirService.class); 12 | 13 | public ChangeDirService() { 14 | LOG.debug("*** ChangeDirService ***"); 15 | } 16 | 17 | public ResponseStatus cd(String currDataSet, final String target) { 18 | LOG.debug("*** cd ***"); 19 | if (DsnUtil.isMember(target) || DsnUtil.isDataset(target)) { 20 | return new ResponseStatus("success", true, target); 21 | } else if (target.equals("..") && !currDataSet.isBlank()) { 22 | var tokens = currDataSet.split("\\."); 23 | int length = tokens.length - 1; 24 | 25 | var str = new StringBuilder(); 26 | for (var i = 0; i < length; i++) { 27 | str.append(tokens[i]); 28 | str.append("."); 29 | } 30 | 31 | var dataset = str.toString(); 32 | if (dataset.isBlank()) { 33 | return new ResponseStatus(Constants.DATASET_NOT_SPECIFIED, false, currDataSet); 34 | } 35 | dataset = dataset.substring(0, str.length() - 1); 36 | return new ResponseStatus("success", true, dataset); 37 | } else if (target.startsWith(".") && !currDataSet.isBlank()) { 38 | var newDataset = currDataSet + target; 39 | if (DsnUtil.isDataset(newDataset)) { 40 | return new ResponseStatus("success", true, newDataset); 41 | } else { 42 | return new ResponseStatus(Constants.INVALID_DATASET, false, currDataSet); 43 | } 44 | } else { 45 | return new ResponseStatus(Constants.INVALID_DATASET, false, currDataSet); 46 | } 47 | } 48 | 49 | } 50 | -------------------------------------------------------------------------------- /src/main/java/zos/shell/service/change/ChangeWinService.java: -------------------------------------------------------------------------------- 1 | package zos.shell.service.change; 2 | 3 | import org.beryx.textio.TextTerminal; 4 | import org.slf4j.Logger; 5 | import org.slf4j.LoggerFactory; 6 | 7 | public class ChangeWinService { 8 | 9 | private static final Logger LOG = LoggerFactory.getLogger(ChangeWinService.class); 10 | 11 | private final TextTerminal terminal; 12 | 13 | public ChangeWinService(final TextTerminal terminal) { 14 | LOG.debug("*** ChangeWinService ***"); 15 | this.terminal = terminal; 16 | } 17 | 18 | public String setTextColor(final String color) { 19 | LOG.debug("*** setTextColor ***"); 20 | if (color != null) { 21 | terminal.getProperties().setPromptColor(color); 22 | terminal.getProperties().setInputColor(color); 23 | return "text color " + color + " set"; 24 | } 25 | return null; 26 | } 27 | 28 | public String setBackGroundColor(final String color) { 29 | LOG.debug("*** setBackGroundColor ***"); 30 | if (color != null) { 31 | terminal.getProperties().setPaneBackgroundColor(color); 32 | return "background color " + color + " set"; 33 | } 34 | return null; 35 | } 36 | 37 | public String setBold(boolean value) { 38 | LOG.debug("*** setBold ***"); 39 | var tp = terminal.getProperties(); 40 | tp.put("prompt.bold", value); 41 | tp.put("input.bold", value); 42 | if (value) { 43 | return "font bold set"; 44 | } 45 | return null; 46 | } 47 | 48 | public String setFontSize(final String size) { 49 | LOG.debug("*** setFontSize ***"); 50 | if (size != null) { 51 | var tp = terminal.getProperties(); 52 | tp.put("prompt.font.size", Integer.valueOf(size)); 53 | tp.put("input.font.size", Integer.valueOf(size)); 54 | return "increased font size to " + size; 55 | } 56 | return null; 57 | } 58 | 59 | public String setPaneHeight(final String height) { 60 | LOG.debug("*** setPaneHeight ***"); 61 | if (height != null) { 62 | try { 63 | terminal.getProperties().setPaneHeight(Integer.parseInt(height)); 64 | } catch (NumberFormatException ignored) { 65 | } 66 | return "pane height " + height + " set"; 67 | } 68 | return null; 69 | } 70 | 71 | public String setPaneWidth(final String width) { 72 | LOG.debug("*** setPaneWidth ***"); 73 | if (width != null) { 74 | try { 75 | terminal.getProperties().setPaneWidth(Integer.parseInt(width)); 76 | } catch (NumberFormatException ignored) { 77 | } 78 | return "pane width " + width + " set"; 79 | } 80 | return null; 81 | } 82 | 83 | } 84 | -------------------------------------------------------------------------------- /src/main/java/zos/shell/service/checksum/CheckSumService.java: -------------------------------------------------------------------------------- 1 | package zos.shell.service.checksum; 2 | 3 | import org.slf4j.Logger; 4 | import org.slf4j.LoggerFactory; 5 | import zos.shell.singleton.CheckSumSingleton; 6 | 7 | import java.io.IOException; 8 | import java.math.BigInteger; 9 | import java.nio.file.Files; 10 | import java.nio.file.Paths; 11 | import java.security.MessageDigest; 12 | import java.security.NoSuchAlgorithmException; 13 | 14 | public class CheckSumService { 15 | 16 | private static final Logger LOG = LoggerFactory.getLogger(CheckSumService.class); 17 | 18 | private static final CheckSumSingleton checkSumSingleton = CheckSumSingleton.getInstance(); 19 | 20 | public CheckSumService() { 21 | LOG.debug("*** CheckSumService ***"); 22 | } 23 | 24 | public void addCheckSum(final String target) { 25 | LOG.debug("*** addCheckSum ***"); 26 | checkSumSingleton.put(target, calculateCheckSum(target)); 27 | } 28 | 29 | public String getCheckSum(final String target) { 30 | LOG.debug("*** getCheckSum ***"); 31 | return checkSumSingleton.get(target); 32 | } 33 | 34 | public String calculateCheckSum(final String target) { 35 | LOG.debug("*** calculateCheckSum ***"); 36 | byte[] hash = new byte[0]; 37 | try { 38 | byte[] data = Files.readAllBytes(Paths.get(target)); 39 | hash = MessageDigest.getInstance("MD5").digest(data); 40 | } catch (IOException | NoSuchAlgorithmException ignored) { 41 | } 42 | return new BigInteger(1, hash).toString(16); 43 | } 44 | 45 | } 46 | -------------------------------------------------------------------------------- /src/main/java/zos/shell/service/console/Console.java: -------------------------------------------------------------------------------- 1 | package zos.shell.service.console; 2 | 3 | import org.slf4j.Logger; 4 | import org.slf4j.LoggerFactory; 5 | import zos.shell.constants.Constants; 6 | import zos.shell.response.ResponseStatus; 7 | import zos.shell.utility.ResponseUtil; 8 | import zowe.client.sdk.rest.exception.ZosmfRequestException; 9 | import zowe.client.sdk.zosconsole.ConsoleConstants; 10 | import zowe.client.sdk.zosconsole.input.IssueConsoleParams; 11 | import zowe.client.sdk.zosconsole.method.IssueConsole; 12 | import zowe.client.sdk.zosconsole.response.ConsoleResponse; 13 | 14 | import java.util.regex.Pattern; 15 | 16 | public class Console { 17 | 18 | private static final Logger LOG = LoggerFactory.getLogger(Console.class); 19 | 20 | private final IssueConsole issueConsole; 21 | private final String consoleName; 22 | 23 | public Console(final IssueConsole issueConsole, final String consoleName) { 24 | LOG.debug("*** Console ***"); 25 | this.issueConsole = issueConsole; 26 | this.consoleName = consoleName; 27 | } 28 | 29 | public ResponseStatus issueConsole(String command) { 30 | LOG.debug("*** issueConsoleCmd ***"); 31 | 32 | var p = Pattern.compile("\"([^\"]*)\""); 33 | var m = p.matcher(command); 34 | while (m.find()) { 35 | command = m.group(1); 36 | } 37 | 38 | ConsoleResponse consoleResponse; 39 | var params = new IssueConsoleParams(command); 40 | params.setProcessResponse(true); 41 | try { 42 | consoleResponse = !(consoleName == null || consoleName.isBlank()) ? 43 | execute(consoleName, params) : execute(params); 44 | } catch (ZosmfRequestException e) { 45 | var errMsg = ResponseUtil.getResponsePhrase(e.getResponse()); 46 | return new ResponseStatus((errMsg != null ? errMsg : e.getMessage()), false); 47 | } 48 | 49 | return new ResponseStatus(Constants.MVS_EXECUTION_SUCCESS + "\n" + 50 | consoleResponse.getCommandResponse().orElse("no data"), true); 51 | } 52 | 53 | private ConsoleResponse execute(final IssueConsoleParams params) throws ZosmfRequestException { 54 | LOG.debug("*** execute issue common command with default consoleName ***"); 55 | return issueConsole.issueCommandCommon(ConsoleConstants.RES_DEF_CN, params); 56 | } 57 | 58 | private ConsoleResponse execute(final String consoleName, final IssueConsoleParams params) 59 | throws ZosmfRequestException { 60 | LOG.debug("*** execute issue common command with consoleName ***"); 61 | return issueConsole.issueCommandCommon(consoleName, params); 62 | } 63 | 64 | } 65 | -------------------------------------------------------------------------------- /src/main/java/zos/shell/service/console/ConsoleService.java: -------------------------------------------------------------------------------- 1 | package zos.shell.service.console; 2 | 3 | import org.slf4j.Logger; 4 | import org.slf4j.LoggerFactory; 5 | import zos.shell.constants.Constants; 6 | import zos.shell.response.ResponseStatus; 7 | import zos.shell.utility.FutureUtil; 8 | import zowe.client.sdk.core.ZosConnection; 9 | import zowe.client.sdk.zosconsole.method.IssueConsole; 10 | 11 | import java.util.concurrent.ExecutorService; 12 | import java.util.concurrent.Executors; 13 | import java.util.concurrent.Future; 14 | 15 | public class ConsoleService { 16 | 17 | private static final Logger LOG = LoggerFactory.getLogger(ConsoleService.class); 18 | 19 | private final ZosConnection connection; 20 | private final long timeout; 21 | 22 | public ConsoleService(ZosConnection connection, long timeout) { 23 | LOG.debug("*** ConsoleService ***"); 24 | this.connection = connection; 25 | this.timeout = timeout; 26 | } 27 | 28 | public ResponseStatus issueConsole(final String consoleName, final String command) { 29 | LOG.debug("*** issueConsole ***"); 30 | ExecutorService pool = Executors.newFixedThreadPool(Constants.THREAD_POOL_MIN); 31 | Future submit = pool.submit(new FutureConsole(new IssueConsole(connection), consoleName, command)); 32 | return FutureUtil.getFutureResponse(submit, pool, timeout); 33 | } 34 | 35 | } 36 | -------------------------------------------------------------------------------- /src/main/java/zos/shell/service/console/FutureConsole.java: -------------------------------------------------------------------------------- 1 | package zos.shell.service.console; 2 | 3 | import zos.shell.response.ResponseStatus; 4 | import zowe.client.sdk.zosconsole.method.IssueConsole; 5 | 6 | import java.util.concurrent.Callable; 7 | 8 | public class FutureConsole extends Console implements Callable { 9 | 10 | private final String command; 11 | 12 | public FutureConsole(final IssueConsole issueConsole, final String consoleName, final String command) { 13 | super(issueConsole, consoleName); 14 | this.command = command; 15 | } 16 | 17 | @Override 18 | public ResponseStatus call() { 19 | return this.issueConsole(command); 20 | } 21 | 22 | } 23 | -------------------------------------------------------------------------------- /src/main/java/zos/shell/service/datasetlst/DatasetListingService.java: -------------------------------------------------------------------------------- 1 | package zos.shell.service.datasetlst; 2 | 3 | import org.slf4j.Logger; 4 | import org.slf4j.LoggerFactory; 5 | import zos.shell.constants.Constants; 6 | import zowe.client.sdk.rest.exception.ZosmfRequestException; 7 | import zowe.client.sdk.zosfiles.dsn.methods.DsnList; 8 | import zowe.client.sdk.zosfiles.dsn.response.Dataset; 9 | 10 | import java.util.List; 11 | import java.util.concurrent.*; 12 | 13 | public class DatasetListingService { 14 | 15 | private static final Logger LOG = LoggerFactory.getLogger(DatasetListingService.class); 16 | 17 | private final DsnList dsnList; 18 | private final long timeout; 19 | 20 | private final ExecutorService pool = Executors.newFixedThreadPool(Constants.THREAD_POOL_MIN); 21 | 22 | public DatasetListingService(final DsnList dsnList, long timeout) { 23 | LOG.debug("*** DatasetListingService ***"); 24 | this.dsnList = dsnList; 25 | this.timeout = timeout; 26 | } 27 | 28 | public List datasetLst(final String dataset) throws ZosmfRequestException { 29 | LOG.debug("*** datasetLst ***"); 30 | Future> submit = pool.submit(new FutureDatasetListing(dsnList, dataset, timeout)); 31 | 32 | List datasets; 33 | try { 34 | datasets = submit.get(timeout, TimeUnit.SECONDS); 35 | } catch (InterruptedException | ExecutionException e) { 36 | LOG.debug("exception error: {}", String.valueOf(e)); 37 | submit.cancel(true); 38 | throw new ZosmfRequestException(e.getMessage() != null && !e.getMessage().isBlank() ? 39 | e.getMessage() : Constants.COMMAND_EXECUTION_ERROR_MSG); 40 | } catch (TimeoutException e) { 41 | submit.cancel(true); 42 | throw new ZosmfRequestException(Constants.TIMEOUT_MESSAGE); 43 | } finally { 44 | pool.shutdown(); 45 | } 46 | 47 | return datasets; 48 | } 49 | 50 | } 51 | -------------------------------------------------------------------------------- /src/main/java/zos/shell/service/datasetlst/FutureDatasetListing.java: -------------------------------------------------------------------------------- 1 | package zos.shell.service.datasetlst; 2 | 3 | import zowe.client.sdk.zosfiles.dsn.input.ListParams; 4 | import zowe.client.sdk.zosfiles.dsn.methods.DsnList; 5 | import zowe.client.sdk.zosfiles.dsn.response.Dataset; 6 | import zowe.client.sdk.zosfiles.dsn.types.AttributeType; 7 | 8 | import java.util.List; 9 | import java.util.concurrent.Callable; 10 | 11 | public class FutureDatasetListing implements Callable> { 12 | 13 | private final String dataset; 14 | private final DsnList dsnList; 15 | private final long timeout; 16 | 17 | public FutureDatasetListing(final DsnList dsnList, final String dataset, final long timeout) { 18 | this.dsnList = dsnList; 19 | this.dataset = dataset; 20 | this.timeout = timeout; 21 | } 22 | 23 | @Override 24 | public List call() throws Exception { 25 | return dsnList.getDatasets(dataset, 26 | new ListParams.Builder().attribute(AttributeType.BASE) 27 | .maxLength("0") // return all 28 | .responseTimeout(String.valueOf(this.timeout)).build()); 29 | } 30 | 31 | } 32 | -------------------------------------------------------------------------------- /src/main/java/zos/shell/service/dsn/concat/Concat.java: -------------------------------------------------------------------------------- 1 | package zos.shell.service.dsn.concat; 2 | 3 | import org.slf4j.Logger; 4 | import org.slf4j.LoggerFactory; 5 | import zos.shell.constants.Constants; 6 | import zos.shell.record.DatasetMember; 7 | import zos.shell.response.ResponseStatus; 8 | import zos.shell.service.dsn.download.Download; 9 | import zos.shell.utility.DsnUtil; 10 | import zos.shell.utility.FileUtil; 11 | import zos.shell.utility.ResponseUtil; 12 | import zowe.client.sdk.rest.exception.ZosmfRequestException; 13 | 14 | import java.io.IOException; 15 | import java.io.InputStream; 16 | 17 | public class Concat { 18 | 19 | private static final Logger LOG = LoggerFactory.getLogger(Concat.class); 20 | 21 | private final Download download; 22 | 23 | public Concat(final Download download) { 24 | LOG.debug("*** Concat ***"); 25 | this.download = download; 26 | } 27 | 28 | public ResponseStatus cat(final String dataset, final String target) { 29 | LOG.debug("*** cat ***"); 30 | InputStream inputStream; 31 | String result; 32 | 33 | var datasetMember = DatasetMember.getDatasetAndMember(target); 34 | try { 35 | if (DsnUtil.isMember(target)) { 36 | // retrieve member data 37 | inputStream = download.getInputStream(String.format("%s(%s)", dataset, target)); 38 | } else if (datasetMember != null || DsnUtil.isDataset(target)) { 39 | // either retrieve sequential dataset data or dataset(member) data 40 | inputStream = download.getInputStream(target); 41 | } else { 42 | return new ResponseStatus(Constants.INVALID_DATASET_AND_MEMBER_COMBINED, false); 43 | } 44 | result = FileUtil.getTextStreamData(inputStream); 45 | return new ResponseStatus(result != null ? result : "no data to display", true); 46 | } catch (ZosmfRequestException e) { 47 | return ResponseUtil.getByteResponseStatus(e); 48 | } catch (IOException e) { 49 | return new ResponseStatus(e.getMessage(), false); 50 | } 51 | } 52 | 53 | } 54 | -------------------------------------------------------------------------------- /src/main/java/zos/shell/service/dsn/concat/ConcatService.java: -------------------------------------------------------------------------------- 1 | package zos.shell.service.dsn.concat; 2 | 3 | import org.slf4j.Logger; 4 | import org.slf4j.LoggerFactory; 5 | import zos.shell.constants.Constants; 6 | import zos.shell.response.ResponseStatus; 7 | import zos.shell.service.dsn.download.Download; 8 | import zos.shell.utility.DsnUtil; 9 | import zos.shell.utility.FutureUtil; 10 | 11 | import java.util.concurrent.ExecutorService; 12 | import java.util.concurrent.Executors; 13 | import java.util.concurrent.Future; 14 | 15 | public class ConcatService { 16 | 17 | private static final Logger LOG = LoggerFactory.getLogger(ConcatService.class); 18 | 19 | private final Download download; 20 | private final long timeout; 21 | 22 | public ConcatService(final Download download, final long timeout) { 23 | LOG.debug("*** ConcatService ***"); 24 | this.download = download; 25 | this.timeout = timeout; 26 | } 27 | 28 | public ResponseStatus cat(final String dataset, final String target) { 29 | LOG.debug("*** cat ***"); 30 | if (DsnUtil.isMember(target) && dataset.isBlank()) { 31 | return new ResponseStatus(Constants.DATASET_NOT_SPECIFIED, false); 32 | } 33 | ExecutorService pool = Executors.newFixedThreadPool(Constants.THREAD_POOL_MIN); 34 | Future submit = pool.submit(new FutureConcat(download, dataset, target)); 35 | return FutureUtil.getFutureResponse(submit, pool, timeout); 36 | } 37 | 38 | } 39 | -------------------------------------------------------------------------------- /src/main/java/zos/shell/service/dsn/concat/FutureConcat.java: -------------------------------------------------------------------------------- 1 | package zos.shell.service.dsn.concat; 2 | 3 | import zos.shell.response.ResponseStatus; 4 | import zos.shell.service.dsn.download.Download; 5 | 6 | import java.util.concurrent.Callable; 7 | 8 | public class FutureConcat extends Concat implements Callable { 9 | 10 | private final String dataset; 11 | private final String target; 12 | 13 | public FutureConcat(final Download download, final String dataset, final String target) { 14 | super(download); 15 | this.dataset = dataset; 16 | this.target = target; 17 | } 18 | 19 | @Override 20 | public ResponseStatus call() { 21 | return this.cat(dataset, target); 22 | } 23 | 24 | } 25 | -------------------------------------------------------------------------------- /src/main/java/zos/shell/service/dsn/copy/Copy.java: -------------------------------------------------------------------------------- 1 | package zos.shell.service.dsn.copy; 2 | 3 | import org.slf4j.Logger; 4 | import org.slf4j.LoggerFactory; 5 | import zos.shell.response.ResponseStatus; 6 | import zos.shell.utility.ResponseUtil; 7 | import zowe.client.sdk.rest.exception.ZosmfRequestException; 8 | import zowe.client.sdk.zosfiles.dsn.methods.DsnCopy; 9 | 10 | public class Copy { 11 | 12 | private static final Logger LOG = LoggerFactory.getLogger(Copy.class); 13 | 14 | private final DsnCopy dsnCopy; 15 | 16 | public Copy(final DsnCopy dsnCopy) { 17 | LOG.debug("*** Copy ***"); 18 | this.dsnCopy = dsnCopy; 19 | } 20 | 21 | public ResponseStatus copy(final String source, final String destination, final boolean isCopyAll) { 22 | LOG.debug("*** copy ***"); 23 | try { 24 | dsnCopy.copy(source, destination, true, isCopyAll); 25 | } catch (ZosmfRequestException e) { 26 | var errMsg = ResponseUtil.getResponsePhrase(e.getResponse()); 27 | return new ResponseStatus((errMsg != null ? errMsg : e.getMessage()), false, source); 28 | } 29 | var msg = isCopyAll ? source + " copied all members to " + destination : source + " copied to " + destination; 30 | return new ResponseStatus(msg, true, source); 31 | } 32 | 33 | } 34 | -------------------------------------------------------------------------------- /src/main/java/zos/shell/service/dsn/copy/FutureCopy.java: -------------------------------------------------------------------------------- 1 | package zos.shell.service.dsn.copy; 2 | 3 | import zos.shell.response.ResponseStatus; 4 | import zowe.client.sdk.zosfiles.dsn.methods.DsnCopy; 5 | 6 | import java.util.concurrent.Callable; 7 | 8 | public class FutureCopy extends Copy implements Callable { 9 | 10 | private final String fromDataSetName; 11 | private final String toDataSetName; 12 | private final boolean isCopyAll; 13 | 14 | public FutureCopy(final DsnCopy DsnCopy, final String fromDataSetName, 15 | final String toDataSetName, final boolean isCopyAll) { 16 | super(DsnCopy); 17 | this.fromDataSetName = fromDataSetName; 18 | this.toDataSetName = toDataSetName; 19 | this.isCopyAll = isCopyAll; 20 | } 21 | 22 | @Override 23 | public ResponseStatus call() { 24 | return this.copy(fromDataSetName, toDataSetName, isCopyAll); 25 | } 26 | 27 | } 28 | -------------------------------------------------------------------------------- /src/main/java/zos/shell/service/dsn/count/CountService.java: -------------------------------------------------------------------------------- 1 | package zos.shell.service.dsn.count; 2 | 3 | import org.slf4j.Logger; 4 | import org.slf4j.LoggerFactory; 5 | import zos.shell.constants.Constants; 6 | import zos.shell.response.ResponseStatus; 7 | import zos.shell.service.datasetlst.DatasetListingService; 8 | import zos.shell.service.memberlst.MemberListingService; 9 | import zos.shell.utility.DsnUtil; 10 | import zowe.client.sdk.rest.exception.ZosmfRequestException; 11 | import zowe.client.sdk.zosfiles.dsn.methods.DsnList; 12 | import zowe.client.sdk.zosfiles.dsn.response.Dataset; 13 | import zowe.client.sdk.zosfiles.dsn.response.Member; 14 | 15 | import java.util.ArrayList; 16 | import java.util.List; 17 | import java.util.concurrent.atomic.AtomicInteger; 18 | 19 | public class CountService { 20 | 21 | private static final Logger LOG = LoggerFactory.getLogger(CountService.class); 22 | 23 | private final DsnList dsnList; 24 | private final long timeout; 25 | 26 | public CountService(final DsnList dsnList, final long timeout) { 27 | LOG.debug("*** CountService ***"); 28 | this.dsnList = dsnList; 29 | this.timeout = timeout; 30 | } 31 | 32 | public ResponseStatus count(final String dataset, final String filter) { 33 | LOG.debug("*** count ***"); 34 | if (!DsnUtil.isMember(dataset) && !DsnUtil.isDataset(dataset)) { 35 | return new ResponseStatus(Constants.DATASET_NOT_SPECIFIED, false); 36 | } 37 | var dataSetCount = new AtomicInteger(); 38 | List datasets = new ArrayList<>(); 39 | List members = new ArrayList<>(); 40 | 41 | if ("members".equalsIgnoreCase(filter)) { 42 | var memberListingService = new MemberListingService(dsnList, timeout); 43 | try { 44 | members = memberListingService.memberLst(dataset); 45 | } catch (ZosmfRequestException e) { 46 | return new ResponseStatus(e.getMessage(), false); 47 | } 48 | } 49 | 50 | if ("datasets".equalsIgnoreCase(filter)) { 51 | var datasetListingService = new DatasetListingService(dsnList, timeout); 52 | try { 53 | datasets = datasetListingService.datasetLst(dataset); 54 | } catch (ZosmfRequestException e) { 55 | return new ResponseStatus(e.getMessage(), false); 56 | } 57 | } 58 | 59 | datasets.forEach(item -> { 60 | if (!item.getDsname().orElse("n\\a").equalsIgnoreCase(dataset)) { 61 | dataSetCount.getAndIncrement(); 62 | } 63 | }); 64 | 65 | return new ResponseStatus(String.valueOf(members.size() + dataSetCount.get()), true); 66 | } 67 | 68 | } 69 | -------------------------------------------------------------------------------- /src/main/java/zos/shell/service/dsn/delete/Delete.java: -------------------------------------------------------------------------------- 1 | package zos.shell.service.dsn.delete; 2 | 3 | import org.slf4j.Logger; 4 | import org.slf4j.LoggerFactory; 5 | import zos.shell.response.ResponseStatus; 6 | import zos.shell.utility.ResponseUtil; 7 | import zowe.client.sdk.rest.exception.ZosmfRequestException; 8 | import zowe.client.sdk.zosfiles.dsn.methods.DsnDelete; 9 | 10 | public class Delete { 11 | 12 | private static final Logger LOG = LoggerFactory.getLogger(Delete.class); 13 | 14 | private static final String SUCCESS_MSG = " deleted"; 15 | private final DsnDelete dsnDelete; 16 | 17 | public Delete(DsnDelete dsnDelete) { 18 | LOG.debug("*** Delete constructor ***"); 19 | this.dsnDelete = dsnDelete; 20 | } 21 | 22 | public ResponseStatus delete(final String dataset, final String member) throws ZosmfRequestException { 23 | LOG.debug("*** delete member ***"); 24 | try { 25 | dsnDelete.delete(dataset, member); 26 | return new ResponseStatus(member + SUCCESS_MSG, true, member); 27 | } catch (ZosmfRequestException e) { 28 | var errMsg = ResponseUtil.getResponsePhrase(e.getResponse()); 29 | throw new ZosmfRequestException((errMsg != null ? errMsg : e.getMessage())); 30 | } 31 | } 32 | 33 | public ResponseStatus delete(final String dataset) throws ZosmfRequestException { 34 | LOG.debug("*** delete dataset ***"); 35 | try { 36 | dsnDelete.delete(dataset); 37 | return new ResponseStatus(dataset + SUCCESS_MSG, true, dataset); 38 | } catch (ZosmfRequestException e) { 39 | var errMsg = ResponseUtil.getResponsePhrase(e.getResponse()); 40 | throw new ZosmfRequestException((errMsg != null ? errMsg : e.getMessage())); 41 | } 42 | } 43 | 44 | } 45 | -------------------------------------------------------------------------------- /src/main/java/zos/shell/service/dsn/delete/FutureDelete.java: -------------------------------------------------------------------------------- 1 | package zos.shell.service.dsn.delete; 2 | 3 | import zos.shell.response.ResponseStatus; 4 | import zowe.client.sdk.rest.exception.ZosmfRequestException; 5 | import zowe.client.sdk.zosfiles.dsn.methods.DsnDelete; 6 | 7 | import java.util.concurrent.Callable; 8 | 9 | public class FutureDelete extends Delete implements Callable { 10 | 11 | private final String dataset; 12 | private final String member; 13 | 14 | public FutureDelete(final DsnDelete dsnDelete, final String dataset, final String member) { 15 | super(dsnDelete); 16 | this.dataset = dataset; 17 | this.member = member; 18 | } 19 | 20 | @Override 21 | public ResponseStatus call() throws ZosmfRequestException { 22 | if (member == null) { 23 | return this.delete(dataset); 24 | } 25 | return this.delete(dataset, member); 26 | } 27 | 28 | } 29 | -------------------------------------------------------------------------------- /src/main/java/zos/shell/service/dsn/download/DatasetInfo.java: -------------------------------------------------------------------------------- 1 | package zos.shell.service.dsn.download; 2 | 3 | import org.slf4j.Logger; 4 | import org.slf4j.LoggerFactory; 5 | import zos.shell.response.ResponseStatus; 6 | import zos.shell.utility.ResponseUtil; 7 | import zowe.client.sdk.rest.exception.ZosmfRequestException; 8 | import zowe.client.sdk.zosfiles.dsn.methods.DsnGet; 9 | import zowe.client.sdk.zosfiles.dsn.response.Dataset; 10 | 11 | public class DatasetInfo { 12 | 13 | private static final Logger LOG = LoggerFactory.getLogger(DatasetInfo.class); 14 | 15 | private final DsnGet dsnGet; 16 | 17 | public DatasetInfo(final DsnGet dsnGet) { 18 | LOG.debug("*** DatasetInfo ***"); 19 | this.dsnGet = dsnGet; 20 | } 21 | 22 | public ResponseStatus dsInfo(final String dataset) { 23 | LOG.debug("*** dsInfo ***"); 24 | 25 | Dataset response; 26 | try { 27 | response = dsnGet.getDsnInfo(dataset); 28 | } catch (ZosmfRequestException e) { 29 | return ResponseUtil.getByteResponseStatus(e); 30 | } 31 | 32 | return new ResponseStatus(response.toString(), true); 33 | } 34 | 35 | } 36 | -------------------------------------------------------------------------------- /src/main/java/zos/shell/service/dsn/download/DownloadAllMembersService.java: -------------------------------------------------------------------------------- 1 | package zos.shell.service.dsn.download; 2 | 3 | import org.slf4j.Logger; 4 | import org.slf4j.LoggerFactory; 5 | import zos.shell.constants.Constants; 6 | import zos.shell.response.ResponseStatus; 7 | import zos.shell.service.memberlst.MemberListingService; 8 | import zos.shell.utility.ResponseUtil; 9 | import zowe.client.sdk.core.ZosConnection; 10 | import zowe.client.sdk.rest.exception.ZosmfRequestException; 11 | import zowe.client.sdk.zosfiles.dsn.methods.DsnList; 12 | import zowe.client.sdk.zosfiles.dsn.response.Member; 13 | 14 | import java.util.ArrayList; 15 | import java.util.List; 16 | 17 | public class DownloadAllMembersService { 18 | 19 | private static final Logger LOG = LoggerFactory.getLogger(DownloadAllMembersService.class); 20 | 21 | private final ZosConnection connection; 22 | private final DownloadMemberListService downloadMembersService; 23 | private final long timeout; 24 | 25 | 26 | public DownloadAllMembersService(final ZosConnection connection, 27 | final DownloadMemberListService downloadMembersService, 28 | final long timeout) { 29 | LOG.debug("*** DownloadAllMembersService ***"); 30 | this.connection = connection; 31 | this.downloadMembersService = downloadMembersService; 32 | this.timeout = timeout; 33 | } 34 | 35 | public List downloadAllMembers(final String target) { 36 | LOG.debug("*** downloadAllMembers ***"); 37 | List results = new ArrayList<>(); 38 | List members; 39 | 40 | try { 41 | members = new MemberListingService(new DsnList(connection), timeout).memberLst(target); 42 | } catch (ZosmfRequestException e) { 43 | var errMsg = ResponseUtil.getResponsePhrase(e.getResponse()); 44 | return List.of(new ResponseStatus((errMsg != null ? errMsg : e.getMessage()), false)); 45 | } 46 | if (members.isEmpty()) { 47 | results.add(new ResponseStatus(Constants.DOWNLOAD_NOTHING_WARNING, false)); 48 | } 49 | results.addAll(downloadMembersService.downloadMembers(target, members)); 50 | return results; 51 | } 52 | 53 | } 54 | -------------------------------------------------------------------------------- /src/main/java/zos/shell/service/dsn/download/DownloadMemberListService.java: -------------------------------------------------------------------------------- 1 | package zos.shell.service.dsn.download; 2 | 3 | import org.slf4j.Logger; 4 | import org.slf4j.LoggerFactory; 5 | import zos.shell.constants.Constants; 6 | import zos.shell.controller.EnvVariableController; 7 | import zos.shell.response.ResponseStatus; 8 | import zos.shell.service.env.EnvVariableService; 9 | import zos.shell.service.path.PathService; 10 | import zos.shell.singleton.ConnSingleton; 11 | import zos.shell.singleton.configuration.ConfigSingleton; 12 | import zowe.client.sdk.core.ZosConnection; 13 | import zowe.client.sdk.zosfiles.dsn.methods.DsnGet; 14 | import zowe.client.sdk.zosfiles.dsn.response.Member; 15 | 16 | import java.util.ArrayList; 17 | import java.util.List; 18 | import java.util.concurrent.*; 19 | 20 | public class DownloadMemberListService { 21 | 22 | private static final Logger LOG = LoggerFactory.getLogger(DownloadMemberListService.class); 23 | 24 | private final ZosConnection connection; 25 | private final boolean isBinary; 26 | private final long timeout; 27 | 28 | public DownloadMemberListService(final ZosConnection connection, final boolean isBinary, 29 | final long timeout) { 30 | LOG.debug("*** DownloadMemberListService ***"); 31 | this.connection = connection; 32 | this.isBinary = isBinary; 33 | this.timeout = timeout; 34 | } 35 | 36 | public List downloadMembers(final String dataset, final List members) { 37 | LOG.debug("*** downloadMembers ***"); 38 | List results = new ArrayList<>(); 39 | ExecutorService pool = Executors.newFixedThreadPool(Constants.THREAD_POOL_MAX); 40 | var futures = new ArrayList>(); 41 | 42 | try { 43 | for (var member : members) { 44 | if (member.getMember().isPresent()) { 45 | String name = member.getMember().get(); 46 | futures.add(pool.submit(new FutureMemberDownload(new DsnGet(connection), 47 | new PathService(ConfigSingleton.getInstance(), ConnSingleton.getInstance(), 48 | new EnvVariableController(new EnvVariableService())), dataset, name, isBinary))); 49 | } 50 | } 51 | 52 | for (var future : futures) { 53 | try { 54 | results.add(future.get(timeout, TimeUnit.SECONDS)); 55 | } catch (InterruptedException | ExecutionException e) { 56 | LOG.debug("exception error: {}", String.valueOf(e)); 57 | future.cancel(true); 58 | results.add(new ResponseStatus(e.getMessage() != null && !e.getMessage().isBlank() ? 59 | e.getMessage() : Constants.EXECUTE_ERROR_MSG, false)); 60 | } catch (TimeoutException e) { 61 | future.cancel(true); 62 | results.add(new ResponseStatus(Constants.TIMEOUT_MESSAGE, false)); 63 | } 64 | } 65 | } finally { 66 | pool.shutdown(); 67 | } 68 | 69 | return results; 70 | } 71 | 72 | } 73 | -------------------------------------------------------------------------------- /src/main/java/zos/shell/service/dsn/download/DownloadMemberService.java: -------------------------------------------------------------------------------- 1 | package zos.shell.service.dsn.download; 2 | 3 | import org.slf4j.Logger; 4 | import org.slf4j.LoggerFactory; 5 | import zos.shell.constants.Constants; 6 | import zos.shell.response.ResponseStatus; 7 | import zos.shell.service.path.PathService; 8 | import zos.shell.utility.FileUtil; 9 | import zowe.client.sdk.core.ZosConnection; 10 | import zowe.client.sdk.zosfiles.dsn.methods.DsnGet; 11 | 12 | import java.io.File; 13 | import java.util.ArrayList; 14 | import java.util.List; 15 | import java.util.concurrent.*; 16 | 17 | public class DownloadMemberService { 18 | 19 | private static final Logger LOG = LoggerFactory.getLogger(DownloadMemberService.class); 20 | 21 | private final ZosConnection connection; 22 | private final PathService pathService; 23 | private final boolean isBinary; 24 | private final long timeout; 25 | 26 | public DownloadMemberService(final ZosConnection connection, final PathService pathService, final boolean isBinary, 27 | final long timeout) { 28 | LOG.debug("*** DownloadMemberService ***"); 29 | this.connection = connection; 30 | this.pathService = pathService; 31 | this.isBinary = isBinary; 32 | this.timeout = timeout; 33 | } 34 | 35 | public List downloadMember(final String dataset, String target) { 36 | LOG.debug("*** downloadMember ***"); 37 | List results = new ArrayList<>(); 38 | ExecutorService pool = Executors.newFixedThreadPool(Constants.THREAD_POOL_MIN); 39 | Future submit = null; 40 | 41 | try { 42 | submit = pool.submit(new FutureMemberDownload(new DsnGet(connection), pathService, dataset, target, isBinary)); 43 | results.add(submit.get(timeout, TimeUnit.SECONDS)); 44 | } catch (InterruptedException | ExecutionException e) { 45 | LOG.debug("exception error: {}", String.valueOf(e)); 46 | submit.cancel(true); 47 | results.add(new ResponseStatus(e.getMessage() != null && !e.getMessage().isBlank() ? 48 | e.getMessage() : Constants.COMMAND_EXECUTION_ERROR_MSG, false)); 49 | } catch (TimeoutException e) { 50 | submit.cancel(true); 51 | results.add(new ResponseStatus(Constants.TIMEOUT_MESSAGE, false)); 52 | } finally { 53 | pool.shutdown(); 54 | } 55 | 56 | if (results.get(0).isStatus()) { 57 | var file = new File(results.get(0).getOptionalData()); 58 | FileUtil.openFileLocation(file.getAbsolutePath()); 59 | return results; 60 | } 61 | 62 | return results; 63 | } 64 | 65 | } 66 | -------------------------------------------------------------------------------- /src/main/java/zos/shell/service/dsn/download/DownloadMembersService.java: -------------------------------------------------------------------------------- 1 | package zos.shell.service.dsn.download; 2 | 3 | import org.slf4j.Logger; 4 | import org.slf4j.LoggerFactory; 5 | import zos.shell.constants.Constants; 6 | import zos.shell.response.ResponseStatus; 7 | import zos.shell.service.memberlst.MemberListingService; 8 | import zos.shell.utility.DsnUtil; 9 | import zos.shell.utility.ResponseUtil; 10 | import zowe.client.sdk.core.ZosConnection; 11 | import zowe.client.sdk.rest.exception.ZosmfRequestException; 12 | import zowe.client.sdk.zosfiles.dsn.methods.DsnList; 13 | import zowe.client.sdk.zosfiles.dsn.response.Member; 14 | 15 | import java.util.ArrayList; 16 | import java.util.List; 17 | 18 | public class DownloadMembersService { 19 | 20 | private static final Logger LOG = LoggerFactory.getLogger(DownloadMembersService.class); 21 | 22 | private final ZosConnection connection; 23 | private final DownloadMemberListService downloadMembersService; 24 | private final long timeout; 25 | 26 | public DownloadMembersService(final ZosConnection connection, 27 | final DownloadMemberListService downloadMembersService, 28 | final long timeout) { 29 | LOG.debug("*** DownloadMembersService ***"); 30 | this.connection = connection; 31 | this.downloadMembersService = downloadMembersService; 32 | this.timeout = timeout; 33 | } 34 | 35 | public List downloadMembers(final String dataset, final String target) { 36 | LOG.debug("*** downloadMembers ***"); 37 | List results = new ArrayList<>(); 38 | List members; 39 | 40 | try { 41 | members = new MemberListingService(new DsnList(connection), timeout).memberLst(dataset); 42 | } catch (ZosmfRequestException e) { 43 | var errMsg = ResponseUtil.getResponsePhrase(e.getResponse()); 44 | return List.of(new ResponseStatus((errMsg != null ? errMsg : e.getMessage()), false)); 45 | } 46 | members = DsnUtil.getMembersByStartsWithFilter(target, members); 47 | if (members.isEmpty()) { 48 | results.add(new ResponseStatus(Constants.DOWNLOAD_NOTHING_WARNING, false)); 49 | } 50 | results.addAll(downloadMembersService.downloadMembers(dataset, members)); 51 | return results; 52 | } 53 | 54 | } 55 | -------------------------------------------------------------------------------- /src/main/java/zos/shell/service/dsn/download/DownloadPdsMemberService.java: -------------------------------------------------------------------------------- 1 | package zos.shell.service.dsn.download; 2 | 3 | import org.slf4j.Logger; 4 | import org.slf4j.LoggerFactory; 5 | import zos.shell.constants.Constants; 6 | import zos.shell.record.DatasetMember; 7 | import zos.shell.response.ResponseStatus; 8 | import zos.shell.service.path.PathService; 9 | import zos.shell.utility.FileUtil; 10 | import zowe.client.sdk.core.ZosConnection; 11 | import zowe.client.sdk.zosfiles.dsn.methods.DsnGet; 12 | 13 | import java.io.File; 14 | import java.util.ArrayList; 15 | import java.util.List; 16 | import java.util.concurrent.*; 17 | 18 | public class DownloadPdsMemberService { 19 | private static final Logger LOG = LoggerFactory.getLogger(DownloadPdsMemberService.class); 20 | 21 | private final ZosConnection connection; 22 | private final PathService pathService; 23 | private final boolean isBinary; 24 | private final long timeout; 25 | 26 | public DownloadPdsMemberService(final ZosConnection connection, final PathService pathService, final boolean isBinary, 27 | final long timeout) { 28 | LOG.debug("*** DownloadPdsMemberService ***"); 29 | this.connection = connection; 30 | this.pathService = pathService; 31 | this.isBinary = isBinary; 32 | this.timeout = timeout; 33 | } 34 | 35 | public List downloadPdsMember(final DatasetMember dataSetMember) { 36 | LOG.debug("*** downloadPdsMember ***"); 37 | List results = new ArrayList<>(); 38 | ExecutorService pool = Executors.newFixedThreadPool(Constants.THREAD_POOL_MIN); 39 | Future submit = null; 40 | 41 | try { 42 | submit = pool.submit(new FutureMemberDownload(new DsnGet(connection), pathService, 43 | dataSetMember.getDataset(), dataSetMember.getMember(), isBinary)); 44 | results.add(submit.get(timeout, TimeUnit.SECONDS)); 45 | } catch (InterruptedException | ExecutionException e) { 46 | LOG.debug("exception error: {}", String.valueOf(e)); 47 | submit.cancel(true); 48 | results.add(new ResponseStatus(e.getMessage() != null && !e.getMessage().isBlank() ? 49 | e.getMessage() : Constants.COMMAND_EXECUTION_ERROR_MSG, false)); 50 | } catch (TimeoutException e) { 51 | submit.cancel(true); 52 | results.add(new ResponseStatus(Constants.TIMEOUT_MESSAGE, false)); 53 | } finally { 54 | pool.shutdown(); 55 | } 56 | 57 | if (results.get(0).isStatus()) { 58 | var file = new File(results.get(0).getOptionalData()); 59 | FileUtil.openFileLocation(file.getAbsolutePath()); 60 | return results; 61 | } 62 | 63 | return results; 64 | } 65 | 66 | } -------------------------------------------------------------------------------- /src/main/java/zos/shell/service/dsn/download/DownloadSeqDatasetService.java: -------------------------------------------------------------------------------- 1 | package zos.shell.service.dsn.download; 2 | 3 | import org.slf4j.Logger; 4 | import org.slf4j.LoggerFactory; 5 | import zos.shell.constants.Constants; 6 | import zos.shell.response.ResponseStatus; 7 | import zos.shell.service.path.PathService; 8 | import zos.shell.utility.FileUtil; 9 | import zowe.client.sdk.core.ZosConnection; 10 | import zowe.client.sdk.zosfiles.dsn.methods.DsnGet; 11 | 12 | import java.io.File; 13 | import java.util.ArrayList; 14 | import java.util.List; 15 | import java.util.concurrent.*; 16 | 17 | public class DownloadSeqDatasetService { 18 | 19 | private static final Logger LOG = LoggerFactory.getLogger(DownloadSeqDatasetService.class); 20 | 21 | private final ZosConnection connection; 22 | private final PathService pathService; 23 | private final boolean isBinary; 24 | private final long timeout; 25 | 26 | public DownloadSeqDatasetService(final ZosConnection connection, final PathService pathService, 27 | final boolean isBinary, final long timeout) { 28 | LOG.debug("*** DownloadSeqDatasetService ***"); 29 | this.connection = connection; 30 | this.pathService = pathService; 31 | this.isBinary = isBinary; 32 | this.timeout = timeout; 33 | } 34 | 35 | public List downloadSeqDataset(final String target) { 36 | LOG.debug("*** downloadSeqDataset ***"); 37 | List results = new ArrayList<>(); 38 | ExecutorService pool = Executors.newFixedThreadPool(Constants.THREAD_POOL_MIN); 39 | Future submit = null; 40 | 41 | try { 42 | if (!isSeqDataset(target)) { 43 | results.add(new ResponseStatus(Constants.DOWNLOAD_NOT_SEQ_DATASET_WARNING, false)); 44 | return results; 45 | } 46 | } catch (ExecutionException | InterruptedException e) { 47 | LOG.debug("exception error: {}", String.valueOf(e)); 48 | results.add(new ResponseStatus(e.getMessage() != null && !e.getMessage().isBlank() ? 49 | e.getMessage() : Constants.COMMAND_EXECUTION_ERROR_MSG, false)); 50 | return results; 51 | } catch (TimeoutException e) { 52 | results.add(new ResponseStatus(Constants.TIMEOUT_MESSAGE, false)); 53 | return results; 54 | } 55 | 56 | try { 57 | submit = pool.submit(new FutureDatasetDownload(new DsnGet(connection), pathService, target, isBinary)); 58 | results.add(submit.get(timeout, TimeUnit.SECONDS)); 59 | } catch (InterruptedException | ExecutionException e) { 60 | LOG.debug("exception error: {}", String.valueOf(e)); 61 | submit.cancel(true); 62 | results.add(new ResponseStatus(e.getMessage() != null && !e.getMessage().isBlank() ? 63 | e.getMessage() : Constants.COMMAND_EXECUTION_ERROR_MSG, false)); 64 | } catch (TimeoutException e) { 65 | submit.cancel(true); 66 | results.add(new ResponseStatus(Constants.TIMEOUT_MESSAGE, false)); 67 | } finally { 68 | pool.shutdown(); 69 | } 70 | 71 | if (results.get(0).isStatus()) { 72 | var file = new File(results.get(0).getOptionalData()); 73 | FileUtil.openFileLocation(file.getAbsolutePath()); 74 | return results; 75 | } 76 | 77 | return results; 78 | } 79 | 80 | private boolean isSeqDataset(String target) throws ExecutionException, InterruptedException, TimeoutException { 81 | LOG.debug("*** isSeqDataset ***"); 82 | 83 | ExecutorService pool = Executors.newFixedThreadPool(Constants.THREAD_POOL_MIN); 84 | ResponseStatus responseStatus; 85 | Future submit; 86 | 87 | try { 88 | submit = pool.submit(new FutureDatasetInfo(new DsnGet(connection), target)); 89 | responseStatus = submit.get(timeout, TimeUnit.SECONDS); 90 | } finally { 91 | pool.shutdown(); 92 | } 93 | 94 | return responseStatus.getMessage().contains("dsorg=Optional[PS]"); 95 | } 96 | 97 | } 98 | -------------------------------------------------------------------------------- /src/main/java/zos/shell/service/dsn/download/FutureDatasetDownload.java: -------------------------------------------------------------------------------- 1 | package zos.shell.service.dsn.download; 2 | 3 | import zos.shell.response.ResponseStatus; 4 | import zos.shell.service.path.PathService; 5 | import zowe.client.sdk.zosfiles.dsn.methods.DsnGet; 6 | 7 | import java.util.concurrent.Callable; 8 | 9 | public class FutureDatasetDownload extends Download implements Callable { 10 | 11 | private final String dataset; 12 | 13 | public FutureDatasetDownload(final DsnGet download, final PathService pathService, final String dataset, 14 | boolean isBinary) { 15 | super(download, pathService, isBinary); 16 | this.dataset = dataset; 17 | } 18 | 19 | @Override 20 | public ResponseStatus call() { 21 | return this.dataset(dataset); 22 | } 23 | 24 | } 25 | -------------------------------------------------------------------------------- /src/main/java/zos/shell/service/dsn/download/FutureDatasetInfo.java: -------------------------------------------------------------------------------- 1 | package zos.shell.service.dsn.download; 2 | 3 | import zos.shell.response.ResponseStatus; 4 | import zowe.client.sdk.zosfiles.dsn.methods.DsnGet; 5 | 6 | import java.util.concurrent.Callable; 7 | 8 | public class FutureDatasetInfo extends DatasetInfo implements Callable { 9 | 10 | private final String dataset; 11 | 12 | public FutureDatasetInfo(final DsnGet dsnGet, final String dataset) { 13 | super(dsnGet); 14 | this.dataset = dataset; 15 | } 16 | 17 | @Override 18 | public ResponseStatus call() { 19 | return this.dsInfo(dataset); 20 | } 21 | 22 | } -------------------------------------------------------------------------------- /src/main/java/zos/shell/service/dsn/download/FutureMemberDownload.java: -------------------------------------------------------------------------------- 1 | package zos.shell.service.dsn.download; 2 | 3 | import zos.shell.response.ResponseStatus; 4 | import zos.shell.service.path.PathService; 5 | import zowe.client.sdk.zosfiles.dsn.methods.DsnGet; 6 | 7 | import java.util.concurrent.Callable; 8 | 9 | public class FutureMemberDownload extends Download implements Callable { 10 | 11 | private final String dataset; 12 | private final String member; 13 | 14 | public FutureMemberDownload(final DsnGet download, final PathService pathService, final String dataset, 15 | final String member, final boolean isBinary) { 16 | super(download, pathService, isBinary); 17 | this.dataset = dataset; 18 | this.member = member; 19 | } 20 | 21 | @Override 22 | public ResponseStatus call() { 23 | return this.member(dataset, member); 24 | } 25 | 26 | } 27 | -------------------------------------------------------------------------------- /src/main/java/zos/shell/service/dsn/edit/Edit.java: -------------------------------------------------------------------------------- 1 | package zos.shell.service.dsn.edit; 2 | 3 | import org.apache.commons.lang3.SystemUtils; 4 | import org.slf4j.Logger; 5 | import org.slf4j.LoggerFactory; 6 | import zos.shell.constants.Constants; 7 | import zos.shell.record.DatasetMember; 8 | import zos.shell.response.ResponseStatus; 9 | import zos.shell.service.checksum.CheckSumService; 10 | import zos.shell.service.dsn.download.Download; 11 | import zos.shell.service.path.PathService; 12 | import zos.shell.utility.DsnUtil; 13 | 14 | import java.io.IOException; 15 | 16 | public class Edit { 17 | 18 | private static final Logger LOG = LoggerFactory.getLogger(Edit.class); 19 | 20 | private final Download download; 21 | private final PathService pathService; 22 | private final CheckSumService checkSumService; 23 | private final Runtime rs = Runtime.getRuntime(); 24 | 25 | public Edit(final Download download, final PathService pathService, final CheckSumService checkSumService) { 26 | LOG.debug("*** Edit ***"); 27 | this.download = download; 28 | this.pathService = pathService; 29 | this.checkSumService = checkSumService; 30 | } 31 | 32 | public ResponseStatus open(final String dataset, final String target) { 33 | LOG.debug("*** open ***"); 34 | ResponseStatus result; 35 | var datasetMember = DatasetMember.getDatasetAndMember(target); 36 | 37 | if (DsnUtil.isMember(target)) { 38 | // member input specified from the current dataset 39 | result = download.member(dataset, target); 40 | this.pathService.createPathsForMember(dataset, target); 41 | } else if (datasetMember != null) { 42 | // dataset(member) input specified 43 | result = download.member(datasetMember.getDataset(), datasetMember.getMember()); 44 | this.pathService.createPathsForMember(datasetMember.getDataset(), datasetMember.getMember()); 45 | } else if (DsnUtil.isDataset(target)) { 46 | // sequential dataset input specified 47 | result = download.dataset(target); 48 | this.pathService.createPathsForSequentialDataset(target); 49 | } else { 50 | return new ResponseStatus(Constants.INVALID_DATASET_AND_MEMBER_COMBINED, false); 51 | } 52 | 53 | try { 54 | if (result.isStatus()) { 55 | String pathFile; 56 | String editorName; 57 | pathFile = this.pathService.getPathWithFile(); 58 | checkSumService.addCheckSum(pathFile); 59 | if (SystemUtils.IS_OS_WINDOWS) { 60 | editorName = Constants.WINDOWS_EDITOR_NAME; 61 | } else if (SystemUtils.IS_OS_MAC_OSX) { 62 | editorName = Constants.MAC_EDITOR_NAME; 63 | } else { 64 | return new ResponseStatus(Constants.OS_ERROR, false); 65 | } 66 | rs.exec(editorName + " " + pathFile); 67 | } else { 68 | return new ResponseStatus(result.getMessage(), false); 69 | } 70 | } catch (IOException e) { 71 | return new ResponseStatus(result.getMessage(), false); 72 | } 73 | 74 | return new ResponseStatus("opened in editor", true); 75 | } 76 | 77 | } 78 | -------------------------------------------------------------------------------- /src/main/java/zos/shell/service/dsn/edit/EditService.java: -------------------------------------------------------------------------------- 1 | package zos.shell.service.dsn.edit; 2 | 3 | import org.slf4j.Logger; 4 | import org.slf4j.LoggerFactory; 5 | import zos.shell.constants.Constants; 6 | import zos.shell.response.ResponseStatus; 7 | import zos.shell.service.checksum.CheckSumService; 8 | import zos.shell.service.dsn.download.Download; 9 | import zos.shell.service.path.PathService; 10 | import zos.shell.utility.DsnUtil; 11 | import zos.shell.utility.FutureUtil; 12 | 13 | import java.util.concurrent.ExecutorService; 14 | import java.util.concurrent.Executors; 15 | import java.util.concurrent.Future; 16 | 17 | public class EditService { 18 | 19 | private static final Logger LOG = LoggerFactory.getLogger(EditService.class); 20 | 21 | private final Download download; 22 | private final PathService pathService; 23 | private final CheckSumService checkSumService; 24 | private final long timeout; 25 | 26 | public EditService(final Download download, final PathService pathService, final CheckSumService checkSumService, 27 | long timeout) { 28 | LOG.debug("*** EditService ***"); 29 | this.download = download; 30 | this.pathService = pathService; 31 | this.checkSumService = checkSumService; 32 | this.timeout = timeout; 33 | } 34 | 35 | public ResponseStatus open(final String dataset, final String target) { 36 | LOG.debug("*** open ***"); 37 | if (DsnUtil.isMember(target) && dataset.isBlank()) { 38 | return new ResponseStatus(Constants.DATASET_NOT_SPECIFIED, false); 39 | } 40 | ExecutorService pool = Executors.newFixedThreadPool(Constants.THREAD_POOL_MIN); 41 | Future submit = pool.submit(new FutureEdit(download, pathService, checkSumService, dataset, target)); 42 | return FutureUtil.getFutureResponse(submit, pool, timeout); 43 | } 44 | 45 | } 46 | -------------------------------------------------------------------------------- /src/main/java/zos/shell/service/dsn/edit/FutureEdit.java: -------------------------------------------------------------------------------- 1 | package zos.shell.service.dsn.edit; 2 | 3 | import zos.shell.response.ResponseStatus; 4 | import zos.shell.service.checksum.CheckSumService; 5 | import zos.shell.service.dsn.download.Download; 6 | import zos.shell.service.path.PathService; 7 | 8 | import java.util.concurrent.Callable; 9 | 10 | public class FutureEdit extends Edit implements Callable { 11 | 12 | private final String dataset; 13 | private final String memberOrDataset; 14 | 15 | public FutureEdit(final Download download, final PathService pathService, final CheckSumService checkSumService, 16 | final String dataset, final String memberOrDataset) { 17 | super(download, pathService, checkSumService); 18 | this.dataset = dataset; 19 | this.memberOrDataset = memberOrDataset; 20 | } 21 | 22 | @Override 23 | public ResponseStatus call() { 24 | return this.open(this.dataset, this.memberOrDataset); 25 | } 26 | 27 | } 28 | -------------------------------------------------------------------------------- /src/main/java/zos/shell/service/dsn/makedir/FutureMakeDirectory.java: -------------------------------------------------------------------------------- 1 | package zos.shell.service.dsn.makedir; 2 | 3 | import zos.shell.response.ResponseStatus; 4 | import zowe.client.sdk.zosfiles.dsn.input.CreateParams; 5 | import zowe.client.sdk.zosfiles.dsn.methods.DsnCreate; 6 | 7 | import java.util.concurrent.Callable; 8 | 9 | public class FutureMakeDirectory extends MakeDirectory implements Callable { 10 | 11 | private final String dataset; 12 | private final CreateParams params; 13 | 14 | public FutureMakeDirectory(final DsnCreate dsnCreate, final String dataset, final CreateParams params) { 15 | super(dsnCreate); 16 | this.dataset = dataset; 17 | this.params = params; 18 | } 19 | 20 | @Override 21 | public ResponseStatus call() { 22 | return this.create(dataset, params); 23 | } 24 | 25 | } 26 | -------------------------------------------------------------------------------- /src/main/java/zos/shell/service/dsn/makedir/MakeDirService.java: -------------------------------------------------------------------------------- 1 | package zos.shell.service.dsn.makedir; 2 | 3 | import org.slf4j.Logger; 4 | import org.slf4j.LoggerFactory; 5 | import zos.shell.constants.Constants; 6 | import zos.shell.response.ResponseStatus; 7 | import zos.shell.utility.FutureUtil; 8 | import zowe.client.sdk.zosfiles.dsn.input.CreateParams; 9 | import zowe.client.sdk.zosfiles.dsn.methods.DsnCreate; 10 | 11 | import java.util.concurrent.ExecutorService; 12 | import java.util.concurrent.Executors; 13 | import java.util.concurrent.Future; 14 | 15 | public class MakeDirService { 16 | 17 | private static final Logger LOG = LoggerFactory.getLogger(MakeDirService.class); 18 | 19 | private final DsnCreate dsnCreate; 20 | private final long timeout; 21 | 22 | public MakeDirService(final DsnCreate dsnCreate, long timeout) { 23 | LOG.debug("*** MakeDirService ***"); 24 | this.dsnCreate = dsnCreate; 25 | this.timeout = timeout; 26 | } 27 | 28 | public ResponseStatus create(final String dataset, final CreateParams params) { 29 | LOG.debug("*** create ***"); 30 | ExecutorService pool = Executors.newFixedThreadPool(Constants.THREAD_POOL_MIN); 31 | Future submit = pool.submit(new FutureMakeDirectory(dsnCreate, dataset, params)); 32 | return FutureUtil.getFutureResponse(submit, pool, timeout); 33 | } 34 | 35 | } 36 | -------------------------------------------------------------------------------- /src/main/java/zos/shell/service/dsn/makedir/MakeDirectory.java: -------------------------------------------------------------------------------- 1 | package zos.shell.service.dsn.makedir; 2 | 3 | import org.slf4j.Logger; 4 | import org.slf4j.LoggerFactory; 5 | import zos.shell.response.ResponseStatus; 6 | import zos.shell.utility.ResponseUtil; 7 | import zowe.client.sdk.rest.exception.ZosmfRequestException; 8 | import zowe.client.sdk.zosfiles.dsn.input.CreateParams; 9 | import zowe.client.sdk.zosfiles.dsn.methods.DsnCreate; 10 | 11 | public class MakeDirectory { 12 | 13 | private static final Logger LOG = LoggerFactory.getLogger(MakeDirectory.class); 14 | 15 | private final DsnCreate dsnCreate; 16 | 17 | public MakeDirectory(final DsnCreate dsnCreate) { 18 | LOG.debug("*** MakeDirectory ***"); 19 | this.dsnCreate = dsnCreate; 20 | } 21 | 22 | public ResponseStatus create(final String dataset, final CreateParams params) { 23 | LOG.debug("*** create ***"); 24 | try { 25 | dsnCreate.create(dataset, params); 26 | } catch (ZosmfRequestException e) { 27 | final String errMsg = ResponseUtil.getResponsePhrase(e.getResponse()); 28 | return new ResponseStatus((errMsg != null ? errMsg : e.getMessage()), false); 29 | } 30 | return new ResponseStatus(dataset + " created successfully...", true); 31 | } 32 | 33 | } 34 | -------------------------------------------------------------------------------- /src/main/java/zos/shell/service/dsn/save/FutureSave.java: -------------------------------------------------------------------------------- 1 | package zos.shell.service.dsn.save; 2 | 3 | import zos.shell.response.ResponseStatus; 4 | import zos.shell.service.checksum.CheckSumService; 5 | import zos.shell.service.path.PathService; 6 | import zowe.client.sdk.zosfiles.dsn.methods.DsnWrite; 7 | 8 | import java.util.concurrent.Callable; 9 | 10 | public class FutureSave extends Save implements Callable { 11 | 12 | private final String dataSet; 13 | private final String memberOrDataset; 14 | 15 | public FutureSave(final DsnWrite dsnWrite, final PathService pathService, final CheckSumService checkSumService, 16 | final String dataSet, final String memberOrDataset) { 17 | super(dsnWrite, pathService, checkSumService); 18 | this.dataSet = dataSet; 19 | this.memberOrDataset = memberOrDataset; 20 | } 21 | 22 | @Override 23 | public ResponseStatus call() { 24 | return this.save(dataSet, memberOrDataset); 25 | } 26 | 27 | } 28 | -------------------------------------------------------------------------------- /src/main/java/zos/shell/service/dsn/save/Save.java: -------------------------------------------------------------------------------- 1 | package zos.shell.service.dsn.save; 2 | 3 | import org.apache.commons.lang3.SystemUtils; 4 | import org.slf4j.Logger; 5 | import org.slf4j.LoggerFactory; 6 | import zos.shell.constants.Constants; 7 | import zos.shell.record.DatasetMember; 8 | import zos.shell.response.ResponseStatus; 9 | import zos.shell.service.checksum.CheckSumService; 10 | import zos.shell.service.path.PathService; 11 | import zos.shell.utility.DsnUtil; 12 | import zos.shell.utility.ResponseUtil; 13 | import zowe.client.sdk.rest.exception.ZosmfRequestException; 14 | import zowe.client.sdk.zosfiles.dsn.methods.DsnWrite; 15 | 16 | import java.io.BufferedReader; 17 | import java.io.FileReader; 18 | import java.io.IOException; 19 | 20 | public class Save { 21 | 22 | private static final Logger LOG = LoggerFactory.getLogger(Save.class); 23 | 24 | private final DsnWrite dsnWrite; 25 | private final PathService pathService; 26 | private final CheckSumService checkSumService; 27 | 28 | public Save(final DsnWrite dsnWrite, final PathService pathService, final CheckSumService checkSumService) { 29 | LOG.debug("*** Save ***"); 30 | this.dsnWrite = dsnWrite; 31 | this.pathService = pathService; 32 | this.checkSumService = checkSumService; 33 | } 34 | 35 | public ResponseStatus save(final String dataset, final String target) { 36 | LOG.debug("*** save ***"); 37 | if (!SystemUtils.IS_OS_WINDOWS && !SystemUtils.IS_OS_MAC_OSX) { 38 | return new ResponseStatus(Constants.OS_ERROR, false); 39 | } 40 | 41 | var datasetMember = DatasetMember.getDatasetAndMember(target); 42 | boolean isSequentialDataset = false; 43 | 44 | if (DsnUtil.isMember(target)) { 45 | // member input specified from the current dataset 46 | this.pathService.createPathsForMember(dataset, target); 47 | } else if (datasetMember != null) { 48 | // dataset(member) input specified 49 | this.pathService.createPathsForMember(datasetMember.getDataset(), datasetMember.getMember()); 50 | } else if (DsnUtil.isDataset(target)) { 51 | // sequential dataset input specified 52 | this.pathService.createPathsForSequentialDataset(target); 53 | isSequentialDataset = true; 54 | } else { 55 | return new ResponseStatus(Constants.INVALID_DATASET_AND_MEMBER_COMBINED, false); 56 | } 57 | 58 | try (var br = new BufferedReader(new FileReader(this.pathService.getPathWithFile()))) { 59 | var sb = new StringBuilder(); 60 | var line = br.readLine(); 61 | 62 | while (line != null) { 63 | sb.append(line); 64 | sb.append(System.lineSeparator()); 65 | line = br.readLine(); 66 | } 67 | var content = sb.toString().replaceAll("(\\r)", ""); 68 | 69 | var checksum = checkSumService.calculateCheckSum(this.pathService.getPathWithFile()); 70 | if (checksum.equals(checkSumService.getCheckSum(this.pathService.getPathWithFile()))) { 71 | return new ResponseStatus("nothing to save, perform editor save and try again...", false); 72 | } 73 | checkSumService.addCheckSum(this.pathService.getPathWithFile()); 74 | 75 | if (isSequentialDataset) { 76 | dsnWrite.write(target, content); 77 | } else if (datasetMember != null) { 78 | dsnWrite.write(datasetMember.getDataset(), datasetMember.getMember(), content); 79 | } else { 80 | dsnWrite.write(dataset, target, content); 81 | } 82 | } catch (ZosmfRequestException e) { 83 | var errMsg = ResponseUtil.getResponsePhrase(e.getResponse()); 84 | return new ResponseStatus((errMsg != null ? errMsg : e.getMessage()), false); 85 | } catch (IOException e) { 86 | return new ResponseStatus(e.getMessage(), false); 87 | } 88 | 89 | return new ResponseStatus(target + " saved", true); 90 | } 91 | 92 | } 93 | -------------------------------------------------------------------------------- /src/main/java/zos/shell/service/dsn/save/SaveService.java: -------------------------------------------------------------------------------- 1 | package zos.shell.service.dsn.save; 2 | 3 | import org.slf4j.Logger; 4 | import org.slf4j.LoggerFactory; 5 | import zos.shell.constants.Constants; 6 | import zos.shell.response.ResponseStatus; 7 | import zos.shell.service.checksum.CheckSumService; 8 | import zos.shell.service.path.PathService; 9 | import zos.shell.utility.DsnUtil; 10 | import zos.shell.utility.FutureUtil; 11 | import zowe.client.sdk.zosfiles.dsn.methods.DsnWrite; 12 | 13 | import java.util.concurrent.ExecutorService; 14 | import java.util.concurrent.Executors; 15 | import java.util.concurrent.Future; 16 | 17 | public class SaveService { 18 | 19 | private static final Logger LOG = LoggerFactory.getLogger(SaveService.class); 20 | 21 | private final DsnWrite dsnWrite; 22 | private final PathService pathService; 23 | private final CheckSumService checkSumService; 24 | private final long timeout; 25 | 26 | public SaveService(final DsnWrite dsnWrite, final PathService pathService, final CheckSumService checkSumService, 27 | final long timeout) { 28 | LOG.debug("*** SaveService ***"); 29 | this.dsnWrite = dsnWrite; 30 | this.pathService = pathService; 31 | this.checkSumService = checkSumService; 32 | this.timeout = timeout; 33 | } 34 | 35 | public ResponseStatus save(final String dataset, final String target) { 36 | LOG.debug("*** save ***"); 37 | if (DsnUtil.isMember(target) && dataset.isBlank()) { 38 | return new ResponseStatus(Constants.DATASET_NOT_SPECIFIED, false); 39 | } 40 | ExecutorService pool = Executors.newFixedThreadPool(Constants.THREAD_POOL_MIN); 41 | Future submit = pool.submit(new FutureSave(dsnWrite, pathService, checkSumService, dataset, target)); 42 | return FutureUtil.getFutureResponse(submit, pool, timeout); 43 | } 44 | 45 | } 46 | 47 | -------------------------------------------------------------------------------- /src/main/java/zos/shell/service/dsn/touch/FutureTouch.java: -------------------------------------------------------------------------------- 1 | package zos.shell.service.dsn.touch; 2 | 3 | import zos.shell.response.ResponseStatus; 4 | import zowe.client.sdk.zosfiles.dsn.methods.DsnWrite; 5 | 6 | import java.util.concurrent.Callable; 7 | 8 | public class FutureTouch extends Touch implements Callable { 9 | 10 | private final String dataset; 11 | private final String member; 12 | 13 | public FutureTouch(final DsnWrite dsnWrite, final String dataset, final String member) { 14 | super(dsnWrite); 15 | this.dataset = dataset; 16 | this.member = member; 17 | } 18 | 19 | @Override 20 | public ResponseStatus call() { 21 | return this.create(this.dataset, this.member); 22 | } 23 | 24 | } 25 | -------------------------------------------------------------------------------- /src/main/java/zos/shell/service/dsn/touch/Touch.java: -------------------------------------------------------------------------------- 1 | package zos.shell.service.dsn.touch; 2 | 3 | import org.slf4j.Logger; 4 | import org.slf4j.LoggerFactory; 5 | import zos.shell.response.ResponseStatus; 6 | import zos.shell.utility.ResponseUtil; 7 | import zowe.client.sdk.rest.exception.ZosmfRequestException; 8 | import zowe.client.sdk.zosfiles.dsn.methods.DsnWrite; 9 | 10 | public class Touch { 11 | 12 | private static final Logger LOG = LoggerFactory.getLogger(Touch.class); 13 | 14 | private static final String SUCCESS_MSG = " created"; 15 | private final DsnWrite dsnWrite; 16 | 17 | public Touch(final DsnWrite dsnWrite) { 18 | LOG.debug("*** Touch ***"); 19 | this.dsnWrite = dsnWrite; 20 | } 21 | 22 | public ResponseStatus create(final String dataset, final String member) { 23 | LOG.debug("*** create ***"); 24 | try { 25 | dsnWrite.write(dataset, member, ""); 26 | return new ResponseStatus(member + SUCCESS_MSG, true); 27 | } catch (ZosmfRequestException e) { 28 | var errMsg = ResponseUtil.getResponsePhrase(e.getResponse()); 29 | return new ResponseStatus((errMsg != null ? errMsg : e.getMessage()), false); 30 | } 31 | } 32 | 33 | } 34 | -------------------------------------------------------------------------------- /src/main/java/zos/shell/service/dsn/touch/TouchService.java: -------------------------------------------------------------------------------- 1 | package zos.shell.service.dsn.touch; 2 | 3 | import org.slf4j.Logger; 4 | import org.slf4j.LoggerFactory; 5 | import zos.shell.constants.Constants; 6 | import zos.shell.record.DatasetMember; 7 | import zos.shell.response.ResponseStatus; 8 | import zos.shell.service.memberlst.MemberListingService; 9 | import zos.shell.utility.DsnUtil; 10 | import zos.shell.utility.FutureUtil; 11 | import zos.shell.utility.ResponseUtil; 12 | import zowe.client.sdk.rest.exception.ZosmfRequestException; 13 | import zowe.client.sdk.zosfiles.dsn.methods.DsnList; 14 | import zowe.client.sdk.zosfiles.dsn.methods.DsnWrite; 15 | 16 | import java.util.concurrent.ExecutorService; 17 | import java.util.concurrent.Executors; 18 | import java.util.concurrent.Future; 19 | 20 | public class TouchService { 21 | 22 | private static final Logger LOG = LoggerFactory.getLogger(TouchService.class); 23 | 24 | private final DsnWrite dsnWrite; 25 | private final DsnList dsnList; 26 | private final long timeout; 27 | 28 | public TouchService(final DsnWrite dsnWrite, final DsnList dsnList, final long timeout) { 29 | LOG.debug("*** TouchService ***"); 30 | this.dsnWrite = dsnWrite; 31 | this.dsnList = dsnList; 32 | this.timeout = timeout; 33 | } 34 | 35 | public ResponseStatus touch(String dataset, String target) { 36 | LOG.debug("*** touch ***"); 37 | ExecutorService pool = Executors.newFixedThreadPool(Constants.THREAD_POOL_MIN); 38 | Future submit; 39 | 40 | var datasetMember = DatasetMember.getDatasetAndMember(target); 41 | 42 | if (DsnUtil.isMember(target) && dataset.isBlank()) { 43 | return new ResponseStatus(Constants.DATASET_NOT_SPECIFIED, false); 44 | } 45 | 46 | if (datasetMember != null) { 47 | dataset = datasetMember.getDataset(); 48 | target = datasetMember.getMember(); 49 | } 50 | 51 | var memberListingService = new MemberListingService(dsnList, timeout); 52 | try { 53 | if (memberListingService.memberExist(dataset, target)) { 54 | return new ResponseStatus(target + " already exists", false); 55 | } 56 | } catch (ZosmfRequestException e) { 57 | var errMsg = ResponseUtil.getResponsePhrase(e.getResponse()); 58 | return new ResponseStatus(errMsg != null ? errMsg : e.getMessage(), false); 59 | } 60 | submit = pool.submit(new FutureTouch(dsnWrite, dataset, target)); 61 | 62 | return FutureUtil.getFutureResponse(submit, pool, timeout); 63 | } 64 | 65 | } 66 | -------------------------------------------------------------------------------- /src/main/java/zos/shell/service/env/EnvVariableService.java: -------------------------------------------------------------------------------- 1 | package zos.shell.service.env; 2 | 3 | import org.slf4j.Logger; 4 | import org.slf4j.LoggerFactory; 5 | import zos.shell.singleton.EnvVariableSingleton; 6 | 7 | import java.util.Map; 8 | import java.util.regex.Pattern; 9 | 10 | public class EnvVariableService { 11 | 12 | private static final Logger LOG = LoggerFactory.getLogger(EnvVariableService.class); 13 | 14 | private static final EnvVariableSingleton envVariableSingleton = EnvVariableSingleton.getInstance(); 15 | 16 | public EnvVariableService() { 17 | LOG.debug("*** EnvVariableService ***"); 18 | } 19 | 20 | public String getValueByEnvName(final String key) { 21 | LOG.debug("*** getValueByEnvName ***"); 22 | return envVariableSingleton.getVariables().get(key.toUpperCase()) != null ? 23 | envVariableSingleton.getVariables().get(key.toUpperCase()) : ""; 24 | } 25 | 26 | public Map getEnvVariables() { 27 | LOG.debug("*** getEnvVariables ***"); 28 | return envVariableSingleton.getVariables(); 29 | } 30 | 31 | public void setEnvVariable(final String key, String value) { 32 | LOG.debug("*** setEnvVariable ***"); 33 | var p = Pattern.compile("\"([^\"]*)\""); 34 | var m = p.matcher(value); 35 | while (m.find()) { 36 | value = m.group(1); 37 | } 38 | envVariableSingleton.getVariables().put(key.toUpperCase(), value); 39 | } 40 | 41 | } 42 | -------------------------------------------------------------------------------- /src/main/java/zos/shell/service/grep/FutureGrep.java: -------------------------------------------------------------------------------- 1 | package zos.shell.service.grep; 2 | 3 | import zos.shell.service.dsn.concat.ConcatService; 4 | 5 | import java.util.List; 6 | import java.util.concurrent.Callable; 7 | 8 | public class FutureGrep extends Grep implements Callable> { 9 | 10 | private final String dataset; 11 | private final String target; 12 | 13 | public FutureGrep(final ConcatService concatenate, final String dataset, final String target, 14 | final String pattern, final boolean withMember) { 15 | super(concatenate, pattern, withMember); 16 | this.dataset = dataset; 17 | this.target = target; 18 | } 19 | 20 | @Override 21 | public List call() { 22 | return this.search(dataset, target); 23 | } 24 | 25 | } 26 | -------------------------------------------------------------------------------- /src/main/java/zos/shell/service/history/CircularLinkedList.java: -------------------------------------------------------------------------------- 1 | package zos.shell.service.history; 2 | 3 | import zos.shell.constants.Constants; 4 | 5 | public class CircularLinkedList { 6 | 7 | public Node currNode = null; 8 | public Node head = null; 9 | public Node tail = null; 10 | private int size = 0; 11 | 12 | // this function will add the new node at the end of the list. 13 | public void add(T data) { 14 | // create a new node 15 | var newNode = new Node<>(data); 16 | 17 | if (size == Constants.HISTORY_SIZE) { 18 | // set the new head pointer 19 | head = head.next; 20 | setTail(newNode); 21 | return; 22 | } 23 | 24 | // checks if the list is empty. 25 | if (head == null) { 26 | // if a list is empty, head, prev and tail would point to the new node. 27 | head = newNode; 28 | tail = newNode; 29 | newNode.next = head; 30 | } else { 31 | setTail(newNode); 32 | } 33 | size++; 34 | } 35 | 36 | public T back() { 37 | if (currNode == null) { 38 | currNode = this.tail; 39 | return (currNode != null ? currNode.data : null); 40 | } 41 | 42 | currNode = currNode.prev; 43 | return (currNode != null ? currNode.data : null); 44 | } 45 | 46 | public T forward() { 47 | if (currNode == null) { 48 | currNode = this.head; 49 | } else { 50 | currNode = currNode.next; 51 | } 52 | return (currNode != null ? currNode.data : null); 53 | } 54 | 55 | public int getSize() { 56 | return size; 57 | } 58 | 59 | private void setTail(Node newNode) { 60 | // tail will point to the new node. 61 | tail.next = newNode; 62 | // hold a temp reference to the current tail node 63 | var temp = tail; 64 | // new node will become new tail. 65 | tail = newNode; 66 | // the circular tail will point to the new head. 67 | tail.next = head; 68 | // link to previous tail node 69 | tail.prev = temp; 70 | // circular double linked 71 | head.prev = tail; 72 | } 73 | 74 | public static class Node { 75 | 76 | private final T data; 77 | private Node next; 78 | private Node prev; 79 | 80 | public Node(T data) { 81 | this.data = data; 82 | } 83 | 84 | public T getData() { 85 | return data; 86 | } 87 | 88 | } 89 | 90 | } 91 | -------------------------------------------------------------------------------- /src/main/java/zos/shell/service/job/browse/BrowseLog.java: -------------------------------------------------------------------------------- 1 | package zos.shell.service.job.browse; 2 | 3 | import org.slf4j.Logger; 4 | import org.slf4j.LoggerFactory; 5 | import zos.shell.constants.Constants; 6 | import zos.shell.response.ResponseStatus; 7 | import zos.shell.utility.ResponseUtil; 8 | import zowe.client.sdk.rest.exception.ZosmfRequestException; 9 | import zowe.client.sdk.zosjobs.input.GetJobParams; 10 | import zowe.client.sdk.zosjobs.input.JobFile; 11 | import zowe.client.sdk.zosjobs.methods.JobGet; 12 | import zowe.client.sdk.zosjobs.response.Job; 13 | 14 | import java.util.ArrayList; 15 | import java.util.List; 16 | import java.util.Optional; 17 | import java.util.concurrent.*; 18 | import java.util.function.Predicate; 19 | 20 | public class BrowseLog { 21 | 22 | private static final Logger LOG = LoggerFactory.getLogger(BrowseLog.class); 23 | 24 | protected final JobGet retrieve; 25 | public List jobs = new ArrayList<>(); 26 | private final boolean isAll; 27 | private final long timeout; 28 | 29 | public BrowseLog(final JobGet retrieve, final boolean isAll, final long timeout) { 30 | LOG.debug("*** BrowseLog ***"); 31 | this.retrieve = retrieve; 32 | this.isAll = isAll; 33 | this.timeout = timeout; 34 | } 35 | 36 | protected ResponseStatus browseLog(final String target) { 37 | LOG.debug("*** browseLog ***"); 38 | var jobParams = new GetJobParams.Builder("*").prefix(target).build(); 39 | try { 40 | jobs = retrieve.getCommon(jobParams); 41 | } catch (ZosmfRequestException e) { 42 | var errMsg = ResponseUtil.getResponsePhrase(e.getResponse()); 43 | return new ResponseStatus((errMsg != null ? errMsg : e.getMessage()), false); 44 | } 45 | if (jobs.isEmpty()) { 46 | var msg = jobParams.getPrefix().orElse("n\\a") + " does not exist, try again..."; 47 | return new ResponseStatus(msg, false); 48 | } 49 | // select the active or input one first; if not found, then get the highest job number 50 | final Predicate isActive = j -> "ACTIVE".equalsIgnoreCase(j.getStatus().orElse("")); 51 | final Predicate isInput = j -> "INPUT".equalsIgnoreCase(j.getStatus().orElse("")); 52 | 53 | Optional jobStillRunning = jobs.stream().filter(isActive.or(isInput)).findAny(); 54 | Job job = jobStillRunning.orElse(jobs.get(0)); 55 | List files; 56 | try { 57 | files = retrieve.getSpoolFilesByJob(job); 58 | } catch (ZosmfRequestException e) { 59 | var msg = ResponseUtil.getResponsePhrase(e.getResponse()); 60 | var errMsg = "error retrieving spool content for job id " + job.getJobId().orElse("n\\a") + 61 | ", " + (msg != null ? msg : e.getMessage()); 62 | return new ResponseStatus(errMsg, false); 63 | } 64 | 65 | ExecutorService pool = Executors.newFixedThreadPool(Constants.THREAD_POOL_MIN); 66 | Future submit = isAll ? pool.submit(new FutureBrowseLog(retrieve, files)) : 67 | pool.submit(new FutureBrowseLog(retrieve, List.of(files.get(0)))); 68 | try { 69 | StringBuilder result = submit.get(timeout, TimeUnit.SECONDS); 70 | return new ResponseStatus(result.toString(), true); 71 | } catch (ExecutionException | InterruptedException e) { 72 | submit.cancel(true); 73 | return new ResponseStatus(e.getMessage() != null && !e.getMessage().isBlank() ? 74 | e.getMessage() : Constants.COMMAND_EXECUTION_ERROR_MSG, false); 75 | } catch (TimeoutException e) { 76 | submit.cancel(true); 77 | return new ResponseStatus(Constants.TIMEOUT_MESSAGE, false); 78 | } finally { 79 | pool.shutdownNow(); 80 | } 81 | } 82 | 83 | } -------------------------------------------------------------------------------- /src/main/java/zos/shell/service/job/browse/BrowseLogService.java: -------------------------------------------------------------------------------- 1 | package zos.shell.service.job.browse; 2 | 3 | import org.slf4j.Logger; 4 | import org.slf4j.LoggerFactory; 5 | import zos.shell.response.ResponseStatus; 6 | import zowe.client.sdk.zosjobs.methods.JobGet; 7 | 8 | public class BrowseLogService extends BrowseLog { 9 | 10 | private static final Logger LOG = LoggerFactory.getLogger(BrowseLogService.class); 11 | 12 | public BrowseLogService(final JobGet retrieve, final boolean isAll, final long timeout) { 13 | super(retrieve, isAll, timeout); 14 | LOG.debug("*** BrowseLogService ***"); 15 | } 16 | 17 | public ResponseStatus browseJob(final String target) { 18 | LOG.debug("*** browseJob ***"); 19 | return browseLog(target); 20 | } 21 | 22 | } 23 | -------------------------------------------------------------------------------- /src/main/java/zos/shell/service/job/browse/FutureBrowseLog.java: -------------------------------------------------------------------------------- 1 | package zos.shell.service.job.browse; 2 | 3 | import zowe.client.sdk.rest.exception.ZosmfRequestException; 4 | import zowe.client.sdk.zosjobs.input.JobFile; 5 | import zowe.client.sdk.zosjobs.methods.JobGet; 6 | 7 | import java.util.List; 8 | import java.util.concurrent.Callable; 9 | 10 | public class FutureBrowseLog implements Callable { 11 | 12 | private final JobGet retrieve; 13 | private final List files; 14 | 15 | public FutureBrowseLog(final JobGet retrieve, final List files) { 16 | this.retrieve = retrieve; 17 | this.files = files; 18 | } 19 | 20 | @Override 21 | public StringBuilder call() { 22 | var str = new StringBuilder(); 23 | files.forEach(file -> { 24 | try { 25 | str.append(List.of(retrieve.getSpoolContent(file) 26 | .replaceAll("[\r\n]+", "\n") 27 | .replaceAll("[\n\n]+", "\n"))); 28 | } catch (ZosmfRequestException ignored) { 29 | } 30 | }); 31 | return str; 32 | } 33 | 34 | } 35 | -------------------------------------------------------------------------------- /src/main/java/zos/shell/service/job/download/DownloadJob.java: -------------------------------------------------------------------------------- 1 | package zos.shell.service.job.download; 2 | 3 | import com.google.common.base.Strings; 4 | import org.slf4j.Logger; 5 | import org.slf4j.LoggerFactory; 6 | import zos.shell.constants.Constants; 7 | import zos.shell.response.ResponseStatus; 8 | import zos.shell.service.job.browse.BrowseLogService; 9 | import zos.shell.service.path.PathService; 10 | import zos.shell.utility.DsnUtil; 11 | import zos.shell.utility.FileUtil; 12 | import zowe.client.sdk.zosjobs.methods.JobGet; 13 | 14 | import java.io.IOException; 15 | import java.util.Comparator; 16 | 17 | public class DownloadJob { 18 | 19 | private static final Logger LOG = LoggerFactory.getLogger(DownloadJob.class); 20 | 21 | private final PathService pathService; 22 | private final BrowseLogService browseLogService; 23 | 24 | public DownloadJob(final JobGet retrieve, final PathService pathService, final boolean isAll, final long timeout) { 25 | LOG.debug("*** DownloadJob ***"); 26 | this.pathService = pathService; 27 | this.browseLogService = new BrowseLogService(retrieve, isAll, timeout); 28 | } 29 | 30 | public ResponseStatus download(final String target) { 31 | LOG.debug("*** download ***"); 32 | if (!DsnUtil.isMember(target)) { 33 | return new ResponseStatus(Constants.INVALID_MEMBER, false); 34 | } 35 | 36 | ResponseStatus responseStatus = browseLogService.browseJob(target); 37 | if (!responseStatus.isStatus() && responseStatus.getMessage().contains("timeout")) { 38 | return new ResponseStatus(Constants.TIMEOUT_MESSAGE, false); 39 | } else if (!responseStatus.isStatus()) { 40 | return new ResponseStatus(responseStatus.getMessage(), false); 41 | } 42 | 43 | var output = responseStatus.getMessage(); 44 | browseLogService.jobs.sort( 45 | Comparator.comparing(job -> job.getJobId().orElse(""), Comparator.reverseOrder())); 46 | String id = browseLogService.jobs.get(0).getJobId().orElse(null); 47 | 48 | this.pathService.createPathsForMember(target, id); 49 | try { 50 | FileUtil.writeTextFile(output, this.pathService.getPath(), this.pathService.getPathWithFile()); 51 | } catch (IOException e) { 52 | return new ResponseStatus(e.getMessage(), false); 53 | } 54 | 55 | var message = Strings.padStart(target, 8, ' ') + Constants.ARROW + 56 | "downloaded to " + this.pathService.getPath(); 57 | return new ResponseStatus(message, true, this.pathService.getPathWithFile()); 58 | } 59 | 60 | } 61 | -------------------------------------------------------------------------------- /src/main/java/zos/shell/service/job/download/DownloadJobService.java: -------------------------------------------------------------------------------- 1 | package zos.shell.service.job.download; 2 | 3 | import org.slf4j.Logger; 4 | import org.slf4j.LoggerFactory; 5 | import zos.shell.constants.Constants; 6 | import zos.shell.response.ResponseStatus; 7 | import zos.shell.service.path.PathService; 8 | import zos.shell.utility.FutureUtil; 9 | import zowe.client.sdk.zosjobs.methods.JobGet; 10 | 11 | import java.util.concurrent.ExecutorService; 12 | import java.util.concurrent.Executors; 13 | import java.util.concurrent.Future; 14 | 15 | public class DownloadJobService { 16 | 17 | private static final Logger LOG = LoggerFactory.getLogger(DownloadJobService.class); 18 | 19 | private final JobGet retrieve; 20 | private final PathService pathService; 21 | private final boolean isAll; 22 | private final long timeout; 23 | 24 | public DownloadJobService(final JobGet retrieve, final PathService pathService, final boolean isAll, 25 | final long timeout) { 26 | LOG.debug("*** DownloadJobService ***"); 27 | this.retrieve = retrieve; 28 | this.pathService = pathService; 29 | this.isAll = isAll; 30 | this.timeout = timeout; 31 | } 32 | 33 | public ResponseStatus download(final String target) { 34 | LOG.debug("*** download ***"); 35 | ExecutorService pool = Executors.newFixedThreadPool(Constants.THREAD_POOL_MIN); 36 | Future submit = pool.submit( 37 | new FutureDownloadJob(retrieve, pathService, target, this.isAll, this.timeout)); 38 | return FutureUtil.getFutureResponse(submit, pool, timeout); 39 | } 40 | 41 | } -------------------------------------------------------------------------------- /src/main/java/zos/shell/service/job/download/FutureDownloadJob.java: -------------------------------------------------------------------------------- 1 | package zos.shell.service.job.download; 2 | 3 | import zos.shell.response.ResponseStatus; 4 | import zos.shell.service.path.PathService; 5 | import zos.shell.utility.FileUtil; 6 | import zowe.client.sdk.zosjobs.methods.JobGet; 7 | 8 | import java.util.concurrent.Callable; 9 | 10 | public class FutureDownloadJob extends DownloadJob implements Callable { 11 | 12 | private final String target; 13 | 14 | public FutureDownloadJob(final JobGet retrieve, final PathService pathService, final String target, 15 | final boolean isAll, final long timeout) { 16 | super(retrieve, pathService, isAll, timeout); 17 | this.target = target; 18 | } 19 | 20 | @Override 21 | public ResponseStatus call() { 22 | ResponseStatus responseStatus = this.download(target); 23 | if (responseStatus != null && responseStatus.isStatus()) { 24 | FileUtil.openFileLocation(responseStatus.getOptionalData()); 25 | } 26 | return responseStatus; 27 | } 28 | 29 | } 30 | -------------------------------------------------------------------------------- /src/main/java/zos/shell/service/job/processlst/FutureProcessListing.java: -------------------------------------------------------------------------------- 1 | package zos.shell.service.job.processlst; 2 | 3 | import zos.shell.response.ResponseStatus; 4 | import zowe.client.sdk.zosjobs.methods.JobGet; 5 | 6 | import java.util.concurrent.Callable; 7 | 8 | public class FutureProcessListing extends ProcessListing implements Callable { 9 | 10 | private final String target; 11 | 12 | public FutureProcessListing(final JobGet jobGet, final String target) { 13 | super(jobGet); 14 | this.target = target; 15 | } 16 | 17 | @Override 18 | public ResponseStatus call() { 19 | return this.processLst(target); 20 | } 21 | 22 | } 23 | -------------------------------------------------------------------------------- /src/main/java/zos/shell/service/job/processlst/ProcessListing.java: -------------------------------------------------------------------------------- 1 | package zos.shell.service.job.processlst; 2 | 3 | import org.slf4j.Logger; 4 | import org.slf4j.LoggerFactory; 5 | import zos.shell.constants.Constants; 6 | import zos.shell.response.ResponseStatus; 7 | import zos.shell.utility.ResponseUtil; 8 | import zowe.client.sdk.rest.exception.ZosmfRequestException; 9 | import zowe.client.sdk.zosjobs.input.GetJobParams; 10 | import zowe.client.sdk.zosjobs.methods.JobGet; 11 | import zowe.client.sdk.zosjobs.response.Job; 12 | 13 | import java.util.Comparator; 14 | import java.util.List; 15 | 16 | public class ProcessListing { 17 | 18 | private static final Logger LOG = LoggerFactory.getLogger(ProcessListing.class); 19 | 20 | private final JobGet jobGet; 21 | private final GetJobParams.Builder getJobParams = new GetJobParams.Builder("*"); 22 | 23 | public ProcessListing(final JobGet jobGet) { 24 | LOG.debug("*** ProcessListing ***"); 25 | this.jobGet = jobGet; 26 | } 27 | 28 | public ResponseStatus processLst(final String target) { 29 | LOG.debug("*** processLst ***"); 30 | List jobs; 31 | try { 32 | if (target != null) { 33 | getJobParams.prefix(target).build(); 34 | } 35 | var params = getJobParams.build(); 36 | jobs = jobGet.getCommon(params); 37 | } catch (ZosmfRequestException e) { 38 | final String errMsg = ResponseUtil.getResponsePhrase(e.getResponse()); 39 | return new ResponseStatus((errMsg != null ? errMsg : e.getMessage()), false); 40 | } 41 | jobs.sort(Comparator.comparing((Job j) -> j.getJobName().orElse("")) 42 | .thenComparing(j -> j.getStatus().orElse("")) 43 | .thenComparing(j -> j.getJobId().orElse(""))); 44 | if (jobs.isEmpty()) { 45 | return new ResponseStatus(Constants.NO_PROCESS_FOUND, false); 46 | } 47 | var str = new StringBuilder(); 48 | jobs.forEach(job -> { 49 | var jobName = job.getJobName().orElse(""); 50 | var jobId = job.getJobId().orElse(""); 51 | var jobStatus = job.getStatus().orElse(""); 52 | str.append(String.format("%-8s %-8s %-8s", jobName, jobId, jobStatus)); 53 | str.append("\n"); 54 | }); 55 | return new ResponseStatus(str.toString(), true); 56 | } 57 | 58 | } 59 | -------------------------------------------------------------------------------- /src/main/java/zos/shell/service/job/processlst/ProcessLstService.java: -------------------------------------------------------------------------------- 1 | package zos.shell.service.job.processlst; 2 | 3 | import org.slf4j.Logger; 4 | import org.slf4j.LoggerFactory; 5 | import zos.shell.constants.Constants; 6 | import zos.shell.response.ResponseStatus; 7 | import zos.shell.utility.FutureUtil; 8 | import zowe.client.sdk.zosjobs.methods.JobGet; 9 | 10 | import java.util.concurrent.ExecutorService; 11 | import java.util.concurrent.Executors; 12 | import java.util.concurrent.Future; 13 | 14 | public class ProcessLstService { 15 | 16 | private static final Logger LOG = LoggerFactory.getLogger(ProcessLstService.class); 17 | 18 | private final JobGet jobGet; 19 | private final long timeout; 20 | 21 | public ProcessLstService(final JobGet jobGet, long timeout) { 22 | LOG.debug("*** ProcessLstService ***"); 23 | this.jobGet = jobGet; 24 | this.timeout = timeout; 25 | } 26 | 27 | public ResponseStatus processLst(final String target) { 28 | LOG.debug("*** processLst ***"); 29 | ExecutorService pool = Executors.newFixedThreadPool(Constants.THREAD_POOL_MIN); 30 | Future submit = pool.submit(new FutureProcessListing(jobGet, target)); 31 | return FutureUtil.getFutureResponse(submit, pool, timeout); 32 | } 33 | 34 | } 35 | -------------------------------------------------------------------------------- /src/main/java/zos/shell/service/job/purge/FuturePurge.java: -------------------------------------------------------------------------------- 1 | package zos.shell.service.job.purge; 2 | 3 | import zos.shell.response.ResponseStatus; 4 | import zos.shell.utility.StrUtil; 5 | import zowe.client.sdk.zosjobs.methods.JobDelete; 6 | import zowe.client.sdk.zosjobs.methods.JobGet; 7 | 8 | import java.util.concurrent.Callable; 9 | 10 | public class FuturePurge extends Purge implements Callable { 11 | 12 | private enum JobIdIdentifier { 13 | 14 | JOB("JOB"), 15 | TSU("TSU"), 16 | STC("STC"); 17 | 18 | private final String value; 19 | 20 | JobIdIdentifier(String value) { 21 | this.value = value; 22 | } 23 | 24 | public String getValue() { 25 | return value; 26 | } 27 | 28 | } 29 | 30 | private final String filter; 31 | 32 | public FuturePurge(final JobDelete delete, final JobGet retrieve, final String filter) { 33 | super(delete, retrieve); 34 | this.filter = filter; 35 | } 36 | 37 | @Override 38 | public ResponseStatus call() { 39 | if ((filter.startsWith(JobIdIdentifier.JOB.getValue()) || 40 | filter.startsWith(JobIdIdentifier.TSU.getValue()) || 41 | filter.startsWith(JobIdIdentifier.STC.getValue()))) { 42 | 43 | var id = filter.substring(3); 44 | if (StrUtil.isStrNum(id)) { 45 | return this.purgeById(filter); 46 | } 47 | } 48 | return this.purgeByName(filter); 49 | } 50 | 51 | } -------------------------------------------------------------------------------- /src/main/java/zos/shell/service/job/purge/Purge.java: -------------------------------------------------------------------------------- 1 | package zos.shell.service.job.purge; 2 | 3 | import org.slf4j.Logger; 4 | import org.slf4j.LoggerFactory; 5 | import zos.shell.response.ResponseStatus; 6 | import zos.shell.utility.DsnUtil; 7 | import zos.shell.utility.ResponseUtil; 8 | import zowe.client.sdk.rest.exception.ZosmfRequestException; 9 | import zowe.client.sdk.zosjobs.input.ModifyJobParams; 10 | import zowe.client.sdk.zosjobs.methods.JobDelete; 11 | import zowe.client.sdk.zosjobs.methods.JobGet; 12 | import zowe.client.sdk.zosjobs.response.Job; 13 | 14 | import java.util.Comparator; 15 | import java.util.List; 16 | 17 | public class Purge { 18 | 19 | private static final Logger LOG = LoggerFactory.getLogger(Purge.class); 20 | 21 | private final JobDelete delete; 22 | private final JobGet retrieve; 23 | 24 | public Purge(final JobDelete delete, final JobGet retrieve) { 25 | LOG.debug("*** Purge ***"); 26 | this.delete = delete; 27 | this.retrieve = retrieve; 28 | } 29 | 30 | public ResponseStatus purgeByName(final String name) { 31 | LOG.debug("*** purgeByName ***"); 32 | if (!DsnUtil.isMember(name)) { 33 | return new ResponseStatus("invalid name or id specified, try again...", false); 34 | } 35 | 36 | List jobs; 37 | try { 38 | jobs = retrieve.getByPrefix(name); 39 | } catch (ZosmfRequestException e) { 40 | final String errMsg = ResponseUtil.getResponsePhrase(e.getResponse()); 41 | return new ResponseStatus((errMsg != null ? errMsg : e.getMessage()), false); 42 | } 43 | 44 | if (jobs.isEmpty()) { 45 | return new ResponseStatus("job not found", false); 46 | } 47 | 48 | jobs.sort(Comparator.comparing(job -> job.getJobId().orElse(""), Comparator.reverseOrder())); 49 | return purge(jobs.get(0)); 50 | } 51 | 52 | public ResponseStatus purgeById(final String id) { 53 | LOG.debug("*** purgeById ***"); 54 | if (!DsnUtil.isMember(id)) { 55 | return new ResponseStatus("invalid name or id specified, try again...", false); 56 | } 57 | 58 | Job job; 59 | try { 60 | job = retrieve.getById(id); 61 | } catch (ZosmfRequestException e) { 62 | final String errMsg = ResponseUtil.getResponsePhrase(e.getResponse()); 63 | return new ResponseStatus((errMsg != null ? errMsg : e.getMessage()), false); 64 | } 65 | 66 | if (job == null) { 67 | return new ResponseStatus("job not found", false); 68 | } 69 | 70 | return purge(job); 71 | } 72 | 73 | private ResponseStatus purge(final Job job) { 74 | LOG.debug("*** purge ***"); 75 | 76 | if (job.getJobId().isEmpty()) { 77 | return new ResponseStatus("job id not found", false); 78 | } 79 | if (job.getJobName().isEmpty()) { 80 | return new ResponseStatus("job name not found", false); 81 | } 82 | if (job.getStatus().isEmpty()) { 83 | return new ResponseStatus("job status not found", false); 84 | } 85 | if (!"OUTPUT".equals(job.getStatus().get())) { 86 | return new ResponseStatus("cannot purge active job", false); 87 | } 88 | 89 | try { 90 | delete.deleteCommon(new ModifyJobParams.Builder( 91 | job.getJobName().get(), job.getJobId().get()).version("1.0").build()); 92 | var msg = "Job Name: " + job.getJobName().get() + ", Job Id: " + job.getJobId().get() + " purged successfully..."; 93 | return new ResponseStatus(msg, true); 94 | } catch (ZosmfRequestException e) { 95 | final String errMsg = ResponseUtil.getResponsePhrase(e.getResponse()); 96 | return new ResponseStatus((errMsg != null ? errMsg : e.getMessage()), false); 97 | } 98 | } 99 | 100 | } 101 | -------------------------------------------------------------------------------- /src/main/java/zos/shell/service/job/purge/PurgeService.java: -------------------------------------------------------------------------------- 1 | package zos.shell.service.job.purge; 2 | 3 | import org.slf4j.Logger; 4 | import org.slf4j.LoggerFactory; 5 | import zos.shell.constants.Constants; 6 | import zos.shell.response.ResponseStatus; 7 | import zos.shell.utility.FutureUtil; 8 | import zowe.client.sdk.zosjobs.methods.JobDelete; 9 | import zowe.client.sdk.zosjobs.methods.JobGet; 10 | 11 | import java.util.concurrent.ExecutorService; 12 | import java.util.concurrent.Executors; 13 | import java.util.concurrent.Future; 14 | 15 | public class PurgeService { 16 | 17 | private static final Logger LOG = LoggerFactory.getLogger(PurgeService.class); 18 | 19 | private final JobDelete delete; 20 | private final JobGet retrieve; 21 | private final long timeout; 22 | 23 | public PurgeService(final JobDelete delete, final JobGet retrieve, final long timeout) { 24 | LOG.debug("*** PurgeService ***"); 25 | this.delete = delete; 26 | this.retrieve = retrieve; 27 | this.timeout = timeout; 28 | } 29 | 30 | public ResponseStatus purge(String filter) { 31 | LOG.debug("*** purge ***"); 32 | ExecutorService pool = Executors.newFixedThreadPool(Constants.THREAD_POOL_MIN); 33 | Future submit = pool.submit(new FuturePurge(delete, retrieve, filter)); 34 | return FutureUtil.getFutureResponse(submit, pool, timeout); 35 | } 36 | 37 | } 38 | -------------------------------------------------------------------------------- /src/main/java/zos/shell/service/job/submit/FutureSubmit.java: -------------------------------------------------------------------------------- 1 | package zos.shell.service.job.submit; 2 | 3 | import zos.shell.response.ResponseStatus; 4 | import zowe.client.sdk.zosjobs.methods.JobSubmit; 5 | 6 | import java.util.concurrent.Callable; 7 | 8 | public class FutureSubmit extends Submit implements Callable { 9 | 10 | private final String dataset; 11 | private final String target; 12 | 13 | public FutureSubmit(final JobSubmit submit, final String dataset, final String target) { 14 | super(submit); 15 | this.dataset = dataset; 16 | this.target = target; 17 | } 18 | 19 | @Override 20 | public ResponseStatus call() { 21 | return this.submit(dataset, target); 22 | } 23 | 24 | } 25 | -------------------------------------------------------------------------------- /src/main/java/zos/shell/service/job/submit/Submit.java: -------------------------------------------------------------------------------- 1 | package zos.shell.service.job.submit; 2 | 3 | import org.slf4j.Logger; 4 | import org.slf4j.LoggerFactory; 5 | import zos.shell.constants.Constants; 6 | import zos.shell.record.DatasetMember; 7 | import zos.shell.response.ResponseStatus; 8 | import zos.shell.utility.ResponseUtil; 9 | import zowe.client.sdk.rest.exception.ZosmfRequestException; 10 | import zowe.client.sdk.zosjobs.methods.JobSubmit; 11 | import zowe.client.sdk.zosjobs.response.Job; 12 | 13 | public class Submit { 14 | 15 | private static final Logger LOG = LoggerFactory.getLogger(Submit.class); 16 | 17 | private final JobSubmit submit; 18 | 19 | public Submit(final JobSubmit submit) { 20 | LOG.debug("*** Submit ***"); 21 | this.submit = submit; 22 | } 23 | 24 | public ResponseStatus submit(String dataset, String target) { 25 | LOG.debug("*** submit ***"); 26 | var datasetMember = DatasetMember.getDatasetAndMember(target); 27 | if (datasetMember != null) { 28 | // dataset(member) input specified 29 | dataset = datasetMember.getDataset(); 30 | target = datasetMember.getMember(); 31 | } 32 | 33 | if (dataset.isBlank()) { 34 | return new ResponseStatus(Constants.DATASET_NOT_SPECIFIED, false); 35 | } 36 | 37 | Job job; 38 | try { 39 | job = submit.submit(String.format("%s(%s)", dataset, target)); 40 | } catch (ZosmfRequestException e) { 41 | final String errMsg = ResponseUtil.getResponsePhrase(e.getResponse()); 42 | return new ResponseStatus((errMsg != null ? errMsg : e.getMessage()), false); 43 | } 44 | return new ResponseStatus("Job Name: " + job.getJobName().orElse("n\\a") + 45 | ", Job Id: " + job.getJobId().orElse("n\\a"), true); 46 | } 47 | 48 | } 49 | -------------------------------------------------------------------------------- /src/main/java/zos/shell/service/job/submit/SubmitService.java: -------------------------------------------------------------------------------- 1 | package zos.shell.service.job.submit; 2 | 3 | import org.slf4j.Logger; 4 | import org.slf4j.LoggerFactory; 5 | import zos.shell.constants.Constants; 6 | import zos.shell.response.ResponseStatus; 7 | import zos.shell.utility.FutureUtil; 8 | import zowe.client.sdk.zosjobs.methods.JobSubmit; 9 | 10 | import java.util.concurrent.ExecutorService; 11 | import java.util.concurrent.Executors; 12 | import java.util.concurrent.Future; 13 | 14 | public class SubmitService { 15 | 16 | private static final Logger LOG = LoggerFactory.getLogger(SubmitService.class); 17 | 18 | private final JobSubmit submit; 19 | private final long timeout; 20 | 21 | public SubmitService(final JobSubmit submit, final long timeout) { 22 | LOG.debug("*** SubmitService ***"); 23 | this.submit = submit; 24 | this.timeout = timeout; 25 | } 26 | 27 | public ResponseStatus submit(final String dataset, final String target) { 28 | LOG.debug("*** submit ***"); 29 | ExecutorService pool = Executors.newFixedThreadPool(Constants.THREAD_POOL_MIN); 30 | Future submit = pool.submit(new FutureSubmit(this.submit, dataset, target)); 31 | return FutureUtil.getFutureResponse(submit, pool, timeout); 32 | } 33 | 34 | } 35 | -------------------------------------------------------------------------------- /src/main/java/zos/shell/service/job/tail/FutureTail.java: -------------------------------------------------------------------------------- 1 | package zos.shell.service.job.tail; 2 | 3 | import org.beryx.textio.TextTerminal; 4 | import zos.shell.response.ResponseStatus; 5 | import zowe.client.sdk.zosjobs.methods.JobGet; 6 | 7 | import java.util.concurrent.Callable; 8 | 9 | public class FutureTail extends Tail implements Callable { 10 | 11 | private final String[] params; 12 | 13 | public FutureTail(final TextTerminal terminal, final JobGet retrieve, final boolean isAll, final long timeout, 14 | final String[] params) { 15 | super(terminal, retrieve, isAll, timeout); 16 | this.params = params; 17 | } 18 | 19 | @Override 20 | public ResponseStatus call() { 21 | return this.tail(params); 22 | } 23 | 24 | } 25 | -------------------------------------------------------------------------------- /src/main/java/zos/shell/service/job/tail/Tail.java: -------------------------------------------------------------------------------- 1 | package zos.shell.service.job.tail; 2 | 3 | import org.beryx.textio.TextTerminal; 4 | import org.slf4j.Logger; 5 | import org.slf4j.LoggerFactory; 6 | import zos.shell.response.ResponseStatus; 7 | import zos.shell.service.job.browse.BrowseLog; 8 | import zowe.client.sdk.zosjobs.methods.JobGet; 9 | 10 | import java.util.Arrays; 11 | import java.util.List; 12 | 13 | public class Tail extends BrowseLog { 14 | 15 | private static final Logger LOG = LoggerFactory.getLogger(Tail.class); 16 | 17 | private final TextTerminal terminal; 18 | 19 | public Tail(final TextTerminal terminal, final JobGet retrieve, final boolean isAll, final long timeout) { 20 | super(retrieve, isAll, timeout); 21 | LOG.debug("*** Tail ***"); 22 | this.terminal = terminal; 23 | } 24 | 25 | public ResponseStatus tail(final String[] params) { 26 | LOG.debug("*** tail ***"); 27 | final ResponseStatus result = browseLog(params[1]); 28 | if (!result.isStatus()) { 29 | return result; 30 | } 31 | var output = Arrays.asList(result.getMessage().split("\n")); 32 | 33 | int size = output.size(); 34 | int lines = 0; 35 | if (params.length == 3) { 36 | if (!"all".equalsIgnoreCase(params[2])) { 37 | lines = Integer.parseInt(params[2]); 38 | } 39 | } 40 | if (params.length == 4) { 41 | lines = Integer.parseInt(params[2]); 42 | } 43 | 44 | if (lines > 0) { 45 | if (lines < size) { 46 | return display(lines, size, output); 47 | } else { 48 | displayAll(output); 49 | return result; 50 | } 51 | } else { 52 | int LINE_LIMIT = 25; 53 | if (size > LINE_LIMIT) { 54 | return display(LINE_LIMIT, size, output); 55 | } else { 56 | displayAll(output); 57 | return result; 58 | } 59 | } 60 | } 61 | 62 | private void displayAll(final List output) { 63 | LOG.debug("*** displayAll ***"); 64 | output.forEach(terminal::println); 65 | } 66 | 67 | private ResponseStatus display(final int lines, final int size, final List output) { 68 | LOG.debug("*** display ***"); 69 | var str = new StringBuilder(); 70 | for (var i = size - lines; i < size; i++) { 71 | terminal.println(output.get(i)); 72 | str.append(output.get(i)).append("\n"); 73 | } 74 | return new ResponseStatus(str.toString(), true); 75 | } 76 | 77 | } -------------------------------------------------------------------------------- /src/main/java/zos/shell/service/job/tail/TailService.java: -------------------------------------------------------------------------------- 1 | package zos.shell.service.job.tail; 2 | 3 | import org.beryx.textio.TextTerminal; 4 | import org.slf4j.Logger; 5 | import org.slf4j.LoggerFactory; 6 | import zos.shell.constants.Constants; 7 | import zos.shell.response.ResponseStatus; 8 | import zos.shell.utility.FutureUtil; 9 | import zowe.client.sdk.zosjobs.methods.JobGet; 10 | 11 | import java.util.concurrent.ExecutorService; 12 | import java.util.concurrent.Executors; 13 | import java.util.concurrent.Future; 14 | 15 | public class TailService { 16 | 17 | private static final Logger LOG = LoggerFactory.getLogger(TailService.class); 18 | 19 | private final TextTerminal terminal; 20 | private final JobGet retrieve; 21 | private final long timeout; 22 | 23 | public TailService(final TextTerminal terminal, final JobGet retrieve, final long timeout) { 24 | LOG.debug("*** TailService ***"); 25 | this.terminal = terminal; 26 | this.retrieve = retrieve; 27 | this.timeout = timeout; 28 | } 29 | 30 | public ResponseStatus tail(String[] params, final boolean isAll) { 31 | LOG.debug("*** tail ***"); 32 | 33 | // example: tail jobOrTaskName 25 all 34 | if (params.length == 4 && "all".equalsIgnoreCase(params[3])) { 35 | try { 36 | Integer.parseInt(params[2]); 37 | } catch (NumberFormatException e) { 38 | return new ResponseStatus(Constants.INVALID_PARAMETER, false); 39 | } 40 | } 41 | 42 | // example: tail jobOrTaskName 25 43 | if (params.length == 3 && !"all".equalsIgnoreCase(params[2])) { 44 | try { 45 | Integer.parseInt(params[2]); 46 | } catch (NumberFormatException e) { 47 | return new ResponseStatus(Constants.INVALID_PARAMETER, false); 48 | } 49 | } 50 | 51 | // example: tail jobOrTaskName 25 25 52 | if (params.length == 4 && !"all".equalsIgnoreCase(params[3])) { 53 | return new ResponseStatus(Constants.INVALID_PARAMETER, false); 54 | } 55 | 56 | return doTail(params, isAll); 57 | } 58 | 59 | private ResponseStatus doTail(String[] params, final boolean isAll) { 60 | ExecutorService pool = Executors.newFixedThreadPool(Constants.THREAD_POOL_MIN); 61 | Future submit = pool.submit(new FutureTail(terminal, retrieve, isAll, timeout, params)); 62 | return FutureUtil.getFutureResponse(submit, pool, timeout); 63 | } 64 | 65 | } 66 | -------------------------------------------------------------------------------- /src/main/java/zos/shell/service/job/terminate/TerminateService.java: -------------------------------------------------------------------------------- 1 | package zos.shell.service.job.terminate; 2 | 3 | import org.slf4j.Logger; 4 | import org.slf4j.LoggerFactory; 5 | import zos.shell.constants.Constants; 6 | import zos.shell.response.ResponseStatus; 7 | import zos.shell.service.console.FutureConsole; 8 | import zos.shell.utility.FutureUtil; 9 | import zowe.client.sdk.zosconsole.method.IssueConsole; 10 | 11 | import java.util.concurrent.ExecutorService; 12 | import java.util.concurrent.Executors; 13 | import java.util.concurrent.Future; 14 | 15 | public class TerminateService { 16 | 17 | private static final Logger LOG = LoggerFactory.getLogger(TerminateService.class); 18 | 19 | private final IssueConsole issueConsole; 20 | private final long timeout; 21 | 22 | public enum Type { 23 | STOP, 24 | CANCEL 25 | } 26 | 27 | public TerminateService(final IssueConsole issueConsole, final long timeout) { 28 | LOG.debug("*** TerminateService ***"); 29 | this.issueConsole = issueConsole; 30 | this.timeout = timeout; 31 | } 32 | 33 | public ResponseStatus terminate(final TerminateService.Type type, final String consoleName, final String target) { 34 | LOG.debug("*** terminate ***"); 35 | String command; 36 | switch (type) { 37 | case STOP: 38 | command = "P " + target; 39 | break; 40 | case CANCEL: 41 | command = "C " + target; 42 | break; 43 | default: 44 | return new ResponseStatus("invalid termination type, try again...", false); 45 | } 46 | 47 | ExecutorService pool = Executors.newFixedThreadPool(Constants.THREAD_POOL_MIN); 48 | Future submit = pool.submit(new FutureConsole(issueConsole, consoleName, command)); 49 | return FutureUtil.getFutureResponse(submit, pool, timeout); 50 | } 51 | 52 | } 53 | -------------------------------------------------------------------------------- /src/main/java/zos/shell/service/localfile/LocalFileService.java: -------------------------------------------------------------------------------- 1 | package zos.shell.service.localfile; 2 | 3 | import org.apache.commons.lang3.SystemUtils; 4 | import org.slf4j.Logger; 5 | import org.slf4j.LoggerFactory; 6 | import zos.shell.constants.Constants; 7 | import zos.shell.singleton.configuration.ConfigSingleton; 8 | 9 | import java.io.File; 10 | import java.util.ArrayList; 11 | import java.util.List; 12 | import java.util.Optional; 13 | import java.util.stream.Collectors; 14 | import java.util.stream.Stream; 15 | 16 | public class LocalFileService { 17 | 18 | private static final Logger LOG = LoggerFactory.getLogger(LocalFileService.class); 19 | 20 | private static final String DIRECTORY_PATH_WINDOWS = Constants.DEFAULT_DOWNLOAD_PATH_WINDOWS + "\\"; 21 | private static final String DIRECTORY_PATH_MAC = Constants.DEFAULT_DOWNLOAD_PATH_MAC + "/"; 22 | 23 | public LocalFileService() { 24 | LOG.debug("*** LocalFileService ***"); 25 | } 26 | 27 | public StringBuilder listFiles(final String target) { 28 | LOG.debug("*** listFiles ***"); 29 | return getFiles(target); 30 | } 31 | 32 | private StringBuilder getFiles(final String target) { 33 | LOG.debug("*** getFiles ***"); 34 | var result = new StringBuilder(); 35 | String path; 36 | var configSettings = ConfigSingleton.getInstance().getConfigSettings(); 37 | var configPath = configSettings != null ? configSettings.getDownloadPath() : ""; 38 | var targetValue = target != null && !target.isBlank() ? target : ""; 39 | if (SystemUtils.IS_OS_WINDOWS) { 40 | var configPathValue = configPath + (!configPath.endsWith("\\") ? "\\" : "") + targetValue; 41 | path = !configPathValue.isBlank() ? configPathValue : DIRECTORY_PATH_WINDOWS + targetValue; 42 | } else if (SystemUtils.IS_OS_MAC_OSX) { 43 | var configPathValue = configPath + (!configPath.endsWith("/") ? "/" : "") + targetValue; 44 | path = !configPathValue.isBlank() ? configPathValue : DIRECTORY_PATH_MAC + targetValue; 45 | } else { 46 | return result.append(Constants.OS_ERROR); 47 | } 48 | if (path.isBlank()) { 49 | return result.append(Constants.NO_FILES); 50 | } 51 | var files = Optional.ofNullable(new File(path).listFiles()); 52 | var results = new ArrayList<>(List.of(path + ":")); 53 | results.addAll(Stream.of(files.orElse(new File[]{})).map(File::getName).sorted().collect(Collectors.toList())); 54 | results.forEach(i -> result.append(i).append("\n")); 55 | return result; 56 | } 57 | 58 | } 59 | -------------------------------------------------------------------------------- /src/main/java/zos/shell/service/memberlst/FutureMemberListing.java: -------------------------------------------------------------------------------- 1 | package zos.shell.service.memberlst; 2 | 3 | import zowe.client.sdk.zosfiles.dsn.input.ListParams; 4 | import zowe.client.sdk.zosfiles.dsn.methods.DsnList; 5 | import zowe.client.sdk.zosfiles.dsn.response.Member; 6 | import zowe.client.sdk.zosfiles.dsn.types.AttributeType; 7 | 8 | import java.util.List; 9 | import java.util.concurrent.Callable; 10 | 11 | public class FutureMemberListing implements Callable> { 12 | 13 | private final String dataset; 14 | private final DsnList dsnList; 15 | private final long timeout; 16 | 17 | public FutureMemberListing(final DsnList dsnList, final String dataset, final long timeout) { 18 | this.dsnList = dsnList; 19 | this.dataset = dataset; 20 | this.timeout = timeout; 21 | } 22 | 23 | @Override 24 | public List call() throws Exception { 25 | return dsnList.getMembers(dataset, 26 | new ListParams.Builder().attribute(AttributeType.BASE) 27 | .maxLength("0") // return all 28 | .responseTimeout(String.valueOf(this.timeout)).build()); 29 | } 30 | 31 | } 32 | -------------------------------------------------------------------------------- /src/main/java/zos/shell/service/memberlst/MemberListingService.java: -------------------------------------------------------------------------------- 1 | package zos.shell.service.memberlst; 2 | 3 | import org.slf4j.Logger; 4 | import org.slf4j.LoggerFactory; 5 | import zos.shell.constants.Constants; 6 | import zowe.client.sdk.rest.exception.ZosmfRequestException; 7 | import zowe.client.sdk.zosfiles.dsn.methods.DsnList; 8 | import zowe.client.sdk.zosfiles.dsn.response.Member; 9 | 10 | import java.util.List; 11 | import java.util.concurrent.*; 12 | import java.util.function.Predicate; 13 | 14 | public class MemberListingService { 15 | 16 | private static final Logger LOG = LoggerFactory.getLogger(MemberListingService.class); 17 | 18 | private final DsnList dsnList; 19 | private final long timeout; 20 | 21 | private final ExecutorService pool = Executors.newFixedThreadPool(Constants.THREAD_POOL_MIN); 22 | 23 | public MemberListingService(final DsnList dsnList, long timeout) { 24 | LOG.debug("*** MemberListingService ***"); 25 | this.dsnList = dsnList; 26 | this.timeout = timeout; 27 | } 28 | 29 | public boolean memberExist(final String dataset, final String member) throws ZosmfRequestException { 30 | LOG.debug("*** memberExist ***"); 31 | Future> submit = pool.submit(new FutureMemberListing(dsnList, dataset, timeout)); 32 | 33 | List members; 34 | try { 35 | members = submit.get(timeout, TimeUnit.SECONDS); 36 | } catch (InterruptedException | ExecutionException e) { 37 | LOG.debug("exception error: {}", String.valueOf(e)); 38 | submit.cancel(true); 39 | throw new ZosmfRequestException(e.getMessage() != null && !e.getMessage().isBlank() ? 40 | e.getMessage() : Constants.COMMAND_EXECUTION_ERROR_MSG); 41 | } catch (TimeoutException e) { 42 | submit.cancel(true); 43 | throw new ZosmfRequestException(Constants.TIMEOUT_MESSAGE); 44 | } finally { 45 | pool.shutdown(); 46 | } 47 | 48 | if (members.isEmpty()) { 49 | return false; 50 | } 51 | 52 | Predicate isMemberPresent = m -> m.getMember().isPresent(); 53 | Predicate isMemberEquals = m -> m.getMember().orElse("").equalsIgnoreCase(member); 54 | return members.stream().anyMatch(isMemberPresent.and(isMemberEquals)); 55 | } 56 | 57 | public List memberLst(final String dataset) throws ZosmfRequestException { 58 | LOG.debug("*** memberLst ***"); 59 | Future> submit = pool.submit(new FutureMemberListing(dsnList, dataset, timeout)); 60 | 61 | List members = List.of(); 62 | try { 63 | members = submit.get(timeout, TimeUnit.SECONDS); 64 | } catch (InterruptedException | ExecutionException e) { 65 | LOG.debug("exception error: {}", String.valueOf(e)); 66 | submit.cancel(true); 67 | } catch (TimeoutException e) { 68 | submit.cancel(true); 69 | throw new ZosmfRequestException(Constants.TIMEOUT_MESSAGE); 70 | } finally { 71 | pool.shutdown(); 72 | } 73 | 74 | return members; 75 | } 76 | 77 | } 78 | -------------------------------------------------------------------------------- /src/main/java/zos/shell/service/omvs/SshService.java: -------------------------------------------------------------------------------- 1 | package zos.shell.service.omvs; 2 | 3 | import org.slf4j.Logger; 4 | import org.slf4j.LoggerFactory; 5 | import zowe.client.sdk.core.SshConnection; 6 | import zowe.client.sdk.zosuss.exception.IssueUssException; 7 | import zowe.client.sdk.zosuss.method.IssueUss; 8 | 9 | import java.util.regex.Pattern; 10 | 11 | public class SshService { 12 | 13 | private static final Logger LOG = LoggerFactory.getLogger(SshService.class); 14 | 15 | private final SshConnection sshConnection; 16 | 17 | public SshService(final SshConnection sshConnection) { 18 | LOG.debug("*** SshService ***"); 19 | this.sshConnection = sshConnection; 20 | } 21 | 22 | public String sshCommand(String command) { 23 | LOG.debug("*** sshCommand ***"); 24 | var p = Pattern.compile("\"([^\"]*)\""); 25 | var m = p.matcher(command); 26 | 27 | while (m.find()) { 28 | command = m.group(1); 29 | } 30 | 31 | try { 32 | var issueUss = new IssueUss(sshConnection); 33 | // 10,000 is the timeout value in milliseconds 34 | return issueUss.issueCommand(command, 10000); 35 | } catch (IssueUssException e) { 36 | LOG.debug("exception error: {}", String.valueOf(e)); 37 | return e.getMessage(); 38 | } 39 | } 40 | 41 | } 42 | -------------------------------------------------------------------------------- /src/main/java/zos/shell/service/path/PathService.java: -------------------------------------------------------------------------------- 1 | package zos.shell.service.path; 2 | 3 | import org.apache.commons.lang3.SystemUtils; 4 | import org.slf4j.Logger; 5 | import org.slf4j.LoggerFactory; 6 | import zos.shell.constants.Constants; 7 | import zos.shell.controller.EnvVariableController; 8 | import zos.shell.singleton.ConnSingleton; 9 | import zos.shell.singleton.configuration.ConfigSingleton; 10 | import zos.shell.utility.DsnUtil; 11 | 12 | public class PathService { 13 | 14 | private static final Logger LOG = LoggerFactory.getLogger(PathService.class); 15 | 16 | private static final String DIRECTORY_PATH_WINDOWS = Constants.DEFAULT_DOWNLOAD_PATH_WINDOWS + "\\"; 17 | 18 | private static final String DIRECTORY_PATH_MAC = Constants.DEFAULT_DOWNLOAD_PATH_MAC + "/"; 19 | 20 | private final ConfigSingleton configSingleton; 21 | private final ConnSingleton connSingleton; 22 | private final EnvVariableController envVariableController; 23 | private String pathToDirectory; 24 | private String pathToDirectoryWithFileName; 25 | 26 | public PathService(final ConfigSingleton configSingleton, final ConnSingleton connSingleton, 27 | final EnvVariableController envVariableController) { 28 | LOG.debug("*** PathService ***"); 29 | this.configSingleton = configSingleton; 30 | this.connSingleton = connSingleton; 31 | this.envVariableController = envVariableController; 32 | } 33 | 34 | public void createPathsForMember(final String dataset, final String target) { 35 | LOG.debug("*** createPathsForMember ***"); 36 | this.initialize(dataset, target); 37 | } 38 | 39 | public void createPathsForSequentialDataset(final String target) { 40 | LOG.debug("*** createPathsForSequentialDataset ***"); 41 | if (DsnUtil.isDataset(target)) { 42 | this.initialize(Constants.SEQUENTIAL_DIRECTORY_LOCATION, target); 43 | } else { 44 | throw new IllegalArgumentException("Expected sequential dataset"); 45 | } 46 | } 47 | 48 | private void initialize(final String dataset, final String target) { 49 | LOG.debug("*** initialize ***"); 50 | var configPath = envVariableController.getValueByEnv("DOWNLOAD_PATH").trim(); 51 | if (configPath.isBlank()) { 52 | configPath = configSingleton.getConfigSettings().getDownloadPath(); 53 | } 54 | 55 | if (SystemUtils.IS_OS_WINDOWS) { 56 | pathToDirectory = !configPath.isBlank() ? configPath + 57 | (!configPath.endsWith("\\") ? "\\" : "") + 58 | connSingleton.getCurrZosConnection().getHost() + "\\" + dataset : 59 | DIRECTORY_PATH_WINDOWS + connSingleton.getCurrZosConnection().getHost() + "\\" + dataset; 60 | pathToDirectoryWithFileName = pathToDirectory + "\\" + target; 61 | } else if (SystemUtils.IS_OS_MAC_OSX) { 62 | pathToDirectory = configPath.isBlank() ? configPath + 63 | (!configPath.endsWith("/") ? "/" : "") + 64 | connSingleton.getCurrZosConnection().getHost() + "/" + dataset : 65 | DIRECTORY_PATH_MAC + connSingleton.getCurrZosConnection().getHost() + "/" + dataset; 66 | pathToDirectoryWithFileName = pathToDirectory + "/" + target; 67 | } else { 68 | throw new IllegalStateException(Constants.OS_ERROR); 69 | } 70 | } 71 | 72 | public String getPath() { 73 | LOG.debug("*** getPath ***"); 74 | return pathToDirectory; 75 | } 76 | 77 | public String getPathWithFile() { 78 | LOG.debug("*** getPathWithFile ***"); 79 | return pathToDirectoryWithFileName; 80 | } 81 | 82 | @Override 83 | public String toString() { 84 | return "PathService{" + 85 | "pathToDirectory='" + pathToDirectory + '\'' + 86 | ", pathToDirectoryWithFileName='" + pathToDirectoryWithFileName + '\'' + 87 | '}'; 88 | } 89 | 90 | } 91 | -------------------------------------------------------------------------------- /src/main/java/zos/shell/service/rename/FutureRenameDataset.java: -------------------------------------------------------------------------------- 1 | package zos.shell.service.rename; 2 | 3 | import zos.shell.response.ResponseStatus; 4 | import zowe.client.sdk.rest.exception.ZosmfRequestException; 5 | import zowe.client.sdk.zosfiles.dsn.methods.DsnRename; 6 | 7 | import java.util.concurrent.Callable; 8 | 9 | public class FutureRenameDataset extends RenameDataset implements Callable { 10 | 11 | private final String source; 12 | private final String destination; 13 | 14 | public FutureRenameDataset(final DsnRename dsnRename, final String source, final String destination) { 15 | super(dsnRename); 16 | this.source = source; 17 | this.destination = destination; 18 | } 19 | 20 | @Override 21 | public ResponseStatus call() throws ZosmfRequestException { 22 | return this.renameDataset(source, destination); 23 | } 24 | 25 | } 26 | -------------------------------------------------------------------------------- /src/main/java/zos/shell/service/rename/FutureRenameMember.java: -------------------------------------------------------------------------------- 1 | package zos.shell.service.rename; 2 | 3 | import zos.shell.response.ResponseStatus; 4 | import zowe.client.sdk.rest.exception.ZosmfRequestException; 5 | import zowe.client.sdk.zosfiles.dsn.methods.DsnRename; 6 | 7 | import java.util.concurrent.Callable; 8 | 9 | public class FutureRenameMember extends RenameMember implements Callable { 10 | 11 | private final String dataset; 12 | private final String source; 13 | private final String destination; 14 | 15 | public FutureRenameMember(final DsnRename dsnRename, final String dataset, final String source, 16 | final String destination) { 17 | super(dsnRename); 18 | this.dataset = dataset; 19 | this.source = source; 20 | this.destination = destination; 21 | } 22 | 23 | @Override 24 | public ResponseStatus call() throws ZosmfRequestException { 25 | return this.renameMember(dataset, source, destination); 26 | } 27 | 28 | } -------------------------------------------------------------------------------- /src/main/java/zos/shell/service/rename/RenameDataset.java: -------------------------------------------------------------------------------- 1 | package zos.shell.service.rename; 2 | 3 | import org.slf4j.Logger; 4 | import org.slf4j.LoggerFactory; 5 | import zos.shell.response.ResponseStatus; 6 | import zos.shell.utility.ResponseUtil; 7 | import zowe.client.sdk.rest.exception.ZosmfRequestException; 8 | import zowe.client.sdk.zosfiles.dsn.methods.DsnRename; 9 | 10 | public class RenameDataset { 11 | 12 | private static final Logger LOG = LoggerFactory.getLogger(RenameDataset.class); 13 | 14 | private static final String SUCCESS_MSG = " renamed to "; 15 | private final DsnRename dsnRename; 16 | 17 | public RenameDataset(DsnRename dsnRename) { 18 | LOG.debug("*** RenameDataset constructor ***"); 19 | this.dsnRename = dsnRename; 20 | } 21 | 22 | public ResponseStatus renameDataset(final String source, final String destination) 23 | throws ZosmfRequestException { 24 | LOG.debug("*** renameDataset ***"); 25 | try { 26 | dsnRename.dataSetName(source, destination); 27 | return new ResponseStatus(source + SUCCESS_MSG + destination, true); 28 | } catch (ZosmfRequestException e) { 29 | var errMsg = ResponseUtil.getResponsePhrase(e.getResponse()); 30 | throw new ZosmfRequestException((errMsg != null ? errMsg : e.getMessage())); 31 | } 32 | } 33 | 34 | } 35 | -------------------------------------------------------------------------------- /src/main/java/zos/shell/service/rename/RenameMember.java: -------------------------------------------------------------------------------- 1 | package zos.shell.service.rename; 2 | 3 | import org.slf4j.Logger; 4 | import org.slf4j.LoggerFactory; 5 | import zos.shell.response.ResponseStatus; 6 | import zos.shell.utility.ResponseUtil; 7 | import zowe.client.sdk.rest.exception.ZosmfRequestException; 8 | import zowe.client.sdk.zosfiles.dsn.methods.DsnRename; 9 | 10 | public class RenameMember { 11 | 12 | private static final Logger LOG = LoggerFactory.getLogger(RenameMember.class); 13 | 14 | private static final String SUCCESS_MSG = " renamed to "; 15 | private final DsnRename dsnRename; 16 | 17 | public RenameMember(DsnRename dsnRename) { 18 | LOG.debug("*** RenameMember constructor ***"); 19 | this.dsnRename = dsnRename; 20 | } 21 | 22 | public ResponseStatus renameMember(final String dataset, final String source, final String destination) 23 | throws ZosmfRequestException { 24 | LOG.debug("*** renameMember ***"); 25 | try { 26 | dsnRename.memberName(dataset, source, destination); 27 | return new ResponseStatus(source + SUCCESS_MSG + destination, true); 28 | } catch (ZosmfRequestException e) { 29 | var errMsg = ResponseUtil.getResponsePhrase(e.getResponse()); 30 | throw new ZosmfRequestException((errMsg != null ? errMsg : e.getMessage())); 31 | } 32 | } 33 | 34 | } 35 | -------------------------------------------------------------------------------- /src/main/java/zos/shell/service/rename/RenameService.java: -------------------------------------------------------------------------------- 1 | package zos.shell.service.rename; 2 | 3 | import org.slf4j.Logger; 4 | import org.slf4j.LoggerFactory; 5 | import zos.shell.constants.Constants; 6 | import zos.shell.response.ResponseStatus; 7 | import zos.shell.utility.DsnUtil; 8 | import zos.shell.utility.FutureUtil; 9 | import zowe.client.sdk.core.ZosConnection; 10 | import zowe.client.sdk.zosfiles.dsn.methods.DsnRename; 11 | 12 | import java.util.concurrent.ExecutorService; 13 | import java.util.concurrent.Executors; 14 | import java.util.concurrent.Future; 15 | 16 | public class RenameService { 17 | 18 | private static final Logger LOG = LoggerFactory.getLogger(RenameService.class); 19 | 20 | private final ZosConnection connection; 21 | private final long timeout; 22 | 23 | public RenameService(final ZosConnection connection, final long timeout) { 24 | LOG.debug("*** RenameService ***"); 25 | this.connection = connection; 26 | this.timeout = timeout; 27 | } 28 | 29 | public ResponseStatus rename(final String dataset, final String source, final String destination) { 30 | LOG.debug("*** rename ***"); 31 | 32 | boolean isMember = DsnUtil.isMember(source); 33 | boolean isDataSet = DsnUtil.isDataset(source); 34 | 35 | if (isMember && !DsnUtil.isMember(destination)) { 36 | return new ResponseStatus(Constants.INVALID_MEMBER, false); 37 | } 38 | 39 | if (isDataSet && !DsnUtil.isDataset(destination)) { 40 | return new ResponseStatus(Constants.INVALID_DATASET, false); 41 | } 42 | 43 | ExecutorService pool = Executors.newFixedThreadPool(Constants.THREAD_POOL_MIN); 44 | Future submit; 45 | 46 | if (isMember) { 47 | if (dataset.isBlank()) { 48 | return new ResponseStatus(Constants.DATASET_NOT_SPECIFIED, false); 49 | } 50 | submit = pool.submit(new FutureRenameMember(new DsnRename(connection), dataset, source, destination)); 51 | return FutureUtil.getFutureResponse(submit, pool, timeout); 52 | } else if (isDataSet) { 53 | submit = pool.submit(new FutureRenameDataset(new DsnRename(connection), source, destination)); 54 | return FutureUtil.getFutureResponse(submit, pool, timeout); 55 | } else { 56 | return new ResponseStatus(Constants.INVALID_COMMAND, false); 57 | } 58 | 59 | } 60 | 61 | } 62 | -------------------------------------------------------------------------------- /src/main/java/zos/shell/service/search/SearchCache.java: -------------------------------------------------------------------------------- 1 | package zos.shell.service.search; 2 | 3 | public class SearchCache { 4 | 5 | private final String name; 6 | private final StringBuilder output; 7 | 8 | public SearchCache(String name, StringBuilder output) { 9 | this.name = name; 10 | this.output = output; 11 | } 12 | 13 | public String getName() { 14 | return name; 15 | } 16 | 17 | public StringBuilder getOutput() { 18 | return output; 19 | } 20 | 21 | @Override 22 | public String toString() { 23 | return "Output{" + 24 | "name='" + name + '\'' + '}'; 25 | } 26 | 27 | } 28 | -------------------------------------------------------------------------------- /src/main/java/zos/shell/service/search/SearchCacheService.java: -------------------------------------------------------------------------------- 1 | package zos.shell.service.search; 2 | 3 | import org.slf4j.Logger; 4 | import org.slf4j.LoggerFactory; 5 | 6 | import java.util.ArrayList; 7 | import java.util.Arrays; 8 | import java.util.List; 9 | import java.util.stream.Collectors; 10 | 11 | public class SearchCacheService { 12 | 13 | private static final Logger LOG = LoggerFactory.getLogger(SearchCacheService.class); 14 | 15 | public SearchCacheService() { 16 | LOG.debug("*** SearchCacheService ***"); 17 | } 18 | 19 | public List search(final SearchCache output, final String text) { 20 | LOG.debug("*** search ***"); 21 | List results = new ArrayList<>(); 22 | if (output == null) { 23 | results.add("nothing to search for..."); 24 | return results; 25 | } 26 | results = Arrays.stream(output.getOutput().toString().split("\n")) 27 | .filter(line -> line.toUpperCase().contains(text.toUpperCase())) 28 | .collect(Collectors.toList()); 29 | if (results.isEmpty()) { 30 | results.add("no results found..."); 31 | return results; 32 | } 33 | return results; 34 | } 35 | 36 | } 37 | -------------------------------------------------------------------------------- /src/main/java/zos/shell/service/tso/FutureTso.java: -------------------------------------------------------------------------------- 1 | package zos.shell.service.tso; 2 | 3 | import zos.shell.response.ResponseStatus; 4 | import zowe.client.sdk.zostso.method.IssueTso; 5 | 6 | import java.util.concurrent.Callable; 7 | 8 | public class FutureTso extends Tso implements Callable { 9 | 10 | private final String command; 11 | 12 | public FutureTso(final IssueTso issueTso, final String accountNumber, final String command) { 13 | super(issueTso, accountNumber); 14 | this.command = command; 15 | } 16 | 17 | @Override 18 | public ResponseStatus call() { 19 | return this.issueCommand(command); 20 | } 21 | 22 | } 23 | -------------------------------------------------------------------------------- /src/main/java/zos/shell/service/tso/Tso.java: -------------------------------------------------------------------------------- 1 | package zos.shell.service.tso; 2 | 3 | import org.slf4j.Logger; 4 | import org.slf4j.LoggerFactory; 5 | import zos.shell.response.ResponseStatus; 6 | import zos.shell.utility.ResponseUtil; 7 | import zowe.client.sdk.rest.exception.ZosmfRequestException; 8 | import zowe.client.sdk.zostso.method.IssueTso; 9 | import zowe.client.sdk.zostso.response.IssueResponse; 10 | 11 | import java.util.regex.Pattern; 12 | 13 | public class Tso { 14 | 15 | private static final Logger LOG = LoggerFactory.getLogger(Tso.class); 16 | 17 | private final zowe.client.sdk.zostso.method.IssueTso issueTso; 18 | private final String accountNumber; 19 | 20 | public Tso(IssueTso issueTso, String accountNumber) { 21 | LOG.debug("*** Tso ***"); 22 | this.issueTso = issueTso; 23 | this.accountNumber = accountNumber; 24 | } 25 | 26 | public ResponseStatus issueCommand(String command) { 27 | LOG.debug("*** issueCommand ***"); 28 | 29 | var p = Pattern.compile("\"([^\"]*)\""); 30 | var m = p.matcher(command); 31 | while (m.find()) { 32 | command = m.group(1); 33 | } 34 | 35 | IssueResponse response; 36 | try { 37 | response = execute(command); 38 | } catch (ZosmfRequestException e) { 39 | final String errMsg = ResponseUtil.getResponsePhrase(e.getResponse()); 40 | return new ResponseStatus((errMsg != null ? errMsg : e.getMessage()), false); 41 | } 42 | 43 | return new ResponseStatus(response.getCommandResponses().orElse("no response"), true); 44 | } 45 | 46 | private IssueResponse execute(final String command) throws ZosmfRequestException { 47 | LOG.debug("*** issue ***"); 48 | return issueTso.issueCommand(accountNumber, command); 49 | } 50 | 51 | } 52 | -------------------------------------------------------------------------------- /src/main/java/zos/shell/service/tso/TsoService.java: -------------------------------------------------------------------------------- 1 | package zos.shell.service.tso; 2 | 3 | import org.slf4j.Logger; 4 | import org.slf4j.LoggerFactory; 5 | import zos.shell.constants.Constants; 6 | import zos.shell.response.ResponseStatus; 7 | import zos.shell.utility.FutureUtil; 8 | import zowe.client.sdk.zostso.method.IssueTso; 9 | 10 | import java.util.concurrent.ExecutorService; 11 | import java.util.concurrent.Executors; 12 | import java.util.concurrent.Future; 13 | 14 | public class TsoService { 15 | 16 | private static final Logger LOG = LoggerFactory.getLogger(TsoService.class); 17 | 18 | private final IssueTso issueTso; 19 | private final long timeout; 20 | 21 | public TsoService(final IssueTso issueTso, final long timeout) { 22 | LOG.debug("*** TsoService ***"); 23 | this.issueTso = issueTso; 24 | this.timeout = timeout; 25 | } 26 | 27 | public ResponseStatus issueCommand(final String accountNumber, final String command) { 28 | LOG.debug("*** issueCommand ***"); 29 | if (accountNumber == null || accountNumber.isBlank()) { 30 | var errMsg = "ACCOUNT_NUMBER is not set, use SET command and try again..."; 31 | return new ResponseStatus(errMsg, false); 32 | } 33 | ExecutorService pool = Executors.newFixedThreadPool(Constants.THREAD_POOL_MIN); 34 | Future submit = pool.submit(new FutureTso(issueTso, accountNumber, command)); 35 | ResponseStatus responseStatus = FutureUtil.getFutureResponse(submit, pool, timeout); 36 | if (!responseStatus.isStatus()) { 37 | return new ResponseStatus(responseStatus.getMessage(), false); 38 | } 39 | return responseStatus; 40 | } 41 | 42 | } 43 | -------------------------------------------------------------------------------- /src/main/java/zos/shell/service/uname/UnameService.java: -------------------------------------------------------------------------------- 1 | package zos.shell.service.uname; 2 | 3 | import org.slf4j.Logger; 4 | import org.slf4j.LoggerFactory; 5 | import zos.shell.constants.Constants; 6 | import zos.shell.response.ResponseStatus; 7 | import zos.shell.service.console.FutureConsole; 8 | import zos.shell.utility.FutureUtil; 9 | import zowe.client.sdk.zosconsole.method.IssueConsole; 10 | 11 | import java.util.concurrent.ExecutorService; 12 | import java.util.concurrent.Executors; 13 | import java.util.concurrent.Future; 14 | 15 | public class UnameService { 16 | 17 | private static final Logger LOG = LoggerFactory.getLogger(UnameService.class); 18 | 19 | private final IssueConsole issueConsole; 20 | private final long timeout; 21 | 22 | public UnameService(final IssueConsole issueConsole, final long timeout) { 23 | LOG.debug("*** UnameService ***"); 24 | this.issueConsole = issueConsole; 25 | this.timeout = timeout; 26 | } 27 | 28 | public String getUname(final String hostName, final String consoleName) { 29 | LOG.debug("*** getUname ***"); 30 | 31 | ExecutorService pool = Executors.newFixedThreadPool(Constants.THREAD_POOL_MIN); 32 | Future submit = pool.submit(new FutureConsole(issueConsole, consoleName, "D IPLINFO")); 33 | ResponseStatus responseStatus = FutureUtil.getFutureResponse(submit, pool, timeout); 34 | 35 | if (!responseStatus.isStatus()) { 36 | return Constants.NO_INFO; 37 | } 38 | var output = responseStatus.getMessage(); 39 | int index = output.indexOf("RELEASE z/OS "); 40 | String zosVersion = null; 41 | if (index >= 0) { 42 | zosVersion = output.substring(index, index + 22); 43 | } 44 | if (zosVersion == null) { 45 | return Constants.NO_INFO; 46 | } 47 | return "hostname: " + hostName + ", " + zosVersion; 48 | } 49 | 50 | } 51 | -------------------------------------------------------------------------------- /src/main/java/zos/shell/service/usermod/UsermodService.java: -------------------------------------------------------------------------------- 1 | package zos.shell.service.usermod; 2 | 3 | import org.slf4j.Logger; 4 | import org.slf4j.LoggerFactory; 5 | import zos.shell.singleton.ConnSingleton; 6 | import zos.shell.singleton.configuration.ConfigSingleton; 7 | import zos.shell.utility.PromptUtil; 8 | import zowe.client.sdk.core.SshConnection; 9 | import zowe.client.sdk.core.ZosConnection; 10 | 11 | public class UsermodService { 12 | 13 | private static final Logger LOG = LoggerFactory.getLogger(UsermodService.class); 14 | 15 | private final String host; 16 | private final String zosmfPort; 17 | private final String username; 18 | private final String password; 19 | private final int sshPort; 20 | 21 | private final int index; 22 | 23 | public UsermodService(final ZosConnection connection, final int index) { 24 | LOG.debug("*** UsermodService ***"); 25 | this.host = connection.getHost(); 26 | this.zosmfPort = connection.getZosmfPort(); 27 | this.username = connection.getUser(); 28 | this.password = connection.getPassword(); 29 | this.sshPort = ConfigSingleton.getInstance().getSshConnectionByIndex(index).getPort(); 30 | this.index = index; 31 | } 32 | 33 | public String changePassword() { 34 | LOG.debug("*** changePassword ***"); 35 | String confirmPassword = null; 36 | var password = ""; 37 | while (confirmPassword == null || !confirmPassword.equals(password)) { 38 | password = PromptUtil.getPromptInfo("password:", true); 39 | confirmPassword = PromptUtil.getPromptInfo("confirm password:", true); 40 | } 41 | var zosConnection = new ZosConnection(this.host, this.zosmfPort, this.username, password); 42 | var sshConnection = new SshConnection(this.host, this.sshPort, this.username, password); 43 | ConfigSingleton.getInstance().setZosConnectionByIndex(zosConnection, index); 44 | ConnSingleton.getInstance().setCurrZosConnection(zosConnection, index); 45 | ConfigSingleton.getInstance().setSshConnectionByIndex(sshConnection, index); 46 | ConnSingleton.getInstance().setCurrSshConnection(sshConnection); 47 | return "password changed"; 48 | } 49 | 50 | public String changeUsername() { 51 | LOG.debug("*** changeUsername ***"); 52 | var username = PromptUtil.getPromptInfo("username:", false); 53 | var zosConnection = new ZosConnection(this.host, this.zosmfPort, username, this.password); 54 | var sshConnection = new SshConnection(this.host, this.sshPort, username, this.password); 55 | ConfigSingleton.getInstance().setZosConnectionByIndex(zosConnection, index); 56 | ConnSingleton.getInstance().setCurrZosConnection(zosConnection, index); 57 | ConfigSingleton.getInstance().setSshConnectionByIndex(sshConnection, index); 58 | ConnSingleton.getInstance().setCurrSshConnection(sshConnection); 59 | return "username changed"; 60 | } 61 | 62 | } 63 | -------------------------------------------------------------------------------- /src/main/java/zos/shell/singleton/CheckSumSingleton.java: -------------------------------------------------------------------------------- 1 | package zos.shell.singleton; 2 | 3 | import org.slf4j.Logger; 4 | import org.slf4j.LoggerFactory; 5 | 6 | import java.util.HashMap; 7 | import java.util.Map; 8 | 9 | public class CheckSumSingleton { 10 | 11 | private static final Logger LOG = LoggerFactory.getLogger(CheckSumSingleton.class); 12 | 13 | public static final Map checksums = new HashMap<>(); 14 | 15 | private static class Holder { 16 | private static final CheckSumSingleton instance = new CheckSumSingleton(); 17 | } 18 | 19 | private CheckSumSingleton() { 20 | LOG.debug("*** CheckSumSingleton ***"); 21 | } 22 | 23 | public static CheckSumSingleton getInstance() { 24 | LOG.debug("*** getInstance ***"); 25 | return CheckSumSingleton.Holder.instance; 26 | } 27 | 28 | public String get(final String target) { 29 | LOG.debug("*** get ***"); 30 | return checksums.get(target); 31 | } 32 | 33 | public void put(final String target, final String value) { 34 | LOG.debug("*** put ***"); 35 | checksums.put(target, value); 36 | } 37 | 38 | } 39 | -------------------------------------------------------------------------------- /src/main/java/zos/shell/singleton/ConnSingleton.java: -------------------------------------------------------------------------------- 1 | package zos.shell.singleton; 2 | 3 | import org.slf4j.Logger; 4 | import org.slf4j.LoggerFactory; 5 | import zowe.client.sdk.core.SshConnection; 6 | import zowe.client.sdk.core.ZosConnection; 7 | 8 | public class ConnSingleton { 9 | 10 | private static final Logger LOG = LoggerFactory.getLogger(ConnSingleton.class); 11 | 12 | private ZosConnection currZosConnection; 13 | private SshConnection currSshConnection; 14 | private int connectionIndex; 15 | 16 | private static class Holder { 17 | private static final ConnSingleton instance = new ConnSingleton(); 18 | } 19 | 20 | private ConnSingleton() { 21 | LOG.debug("*** ConnSingleton ***"); 22 | } 23 | 24 | public static ConnSingleton getInstance() { 25 | LOG.debug("*** getInstance ***"); 26 | return ConnSingleton.Holder.instance; 27 | } 28 | 29 | public ZosConnection getCurrZosConnection() { 30 | LOG.debug("*** getCurrZosConnection ***"); 31 | return currZosConnection; 32 | } 33 | 34 | public void setCurrZosConnection(final ZosConnection currZosConnection, int index) { 35 | LOG.debug("*** setCurrZosConnection ***"); 36 | this.currZosConnection = currZosConnection; 37 | this.connectionIndex = index; 38 | } 39 | 40 | public SshConnection getCurrSshConnection() { 41 | LOG.debug("*** getCurrSshConnection ***"); 42 | return currSshConnection; 43 | } 44 | 45 | public void setCurrSshConnection(final SshConnection currSshConnection) { 46 | LOG.debug("*** setCurrSshConnection ***"); 47 | this.currSshConnection = currSshConnection; 48 | } 49 | 50 | public int getCurrZosConnectionIndex() { 51 | LOG.debug("*** getCurrZosConnectionIndex ***"); 52 | return connectionIndex; 53 | } 54 | 55 | } 56 | -------------------------------------------------------------------------------- /src/main/java/zos/shell/singleton/EnvVariableSingleton.java: -------------------------------------------------------------------------------- 1 | package zos.shell.singleton; 2 | 3 | import org.slf4j.Logger; 4 | import org.slf4j.LoggerFactory; 5 | 6 | import java.util.LinkedHashMap; 7 | import java.util.Map; 8 | 9 | public class EnvVariableSingleton { 10 | 11 | private static final Logger LOG = LoggerFactory.getLogger(EnvVariableSingleton.class); 12 | 13 | private static class Holder { 14 | private static final EnvVariableSingleton instance = new EnvVariableSingleton(); 15 | } 16 | 17 | private final Map variables = new LinkedHashMap<>(); 18 | 19 | private EnvVariableSingleton() { 20 | LOG.debug("*** EnvVariableSingleton ***"); 21 | } 22 | 23 | public static EnvVariableSingleton getInstance() { 24 | LOG.debug("*** getInstance ***"); 25 | return EnvVariableSingleton.Holder.instance; 26 | } 27 | 28 | public Map getVariables() { 29 | LOG.debug("*** getVariables ***"); 30 | return variables; 31 | } 32 | 33 | } 34 | -------------------------------------------------------------------------------- /src/main/java/zos/shell/singleton/HistorySingleton.java: -------------------------------------------------------------------------------- 1 | package zos.shell.singleton; 2 | 3 | import org.beryx.textio.TextTerminal; 4 | import org.slf4j.Logger; 5 | import org.slf4j.LoggerFactory; 6 | import zos.shell.service.history.HistoryService; 7 | 8 | public class HistorySingleton { 9 | 10 | private static final Logger LOG = LoggerFactory.getLogger(HistorySingleton.class); 11 | 12 | private HistoryService history; 13 | 14 | private static class Holder { 15 | private static final HistorySingleton instance = new HistorySingleton(); 16 | } 17 | 18 | private HistorySingleton() { 19 | LOG.debug("*** HistorySingleton ***"); 20 | } 21 | 22 | public static HistorySingleton getInstance() { 23 | LOG.debug("*** getInstance ***"); 24 | return HistorySingleton.Holder.instance; 25 | } 26 | 27 | public HistoryService getHistory() { 28 | LOG.debug("*** getHistory ***"); 29 | return this.history; 30 | } 31 | 32 | public void setHistory(final TextTerminal terminal) { 33 | LOG.debug("*** setHistory ***"); 34 | this.history = new HistoryService(terminal); 35 | } 36 | 37 | } 38 | -------------------------------------------------------------------------------- /src/main/java/zos/shell/singleton/configuration/model/Profile.java: -------------------------------------------------------------------------------- 1 | package zos.shell.singleton.configuration.model; 2 | 3 | public class Profile { 4 | 5 | private String name; 6 | private String hostname; 7 | private String zosmfPort; 8 | private String sshport; 9 | private String username; 10 | private String password; 11 | private String downloadPath; 12 | private String consoleName; 13 | private String accountNumber; 14 | private String browseLimit; 15 | private String prompt; 16 | private Window window; 17 | 18 | public Profile() { 19 | } 20 | 21 | public String getName() { 22 | return name; 23 | } 24 | 25 | public void setName(String name) { 26 | this.name = name; 27 | } 28 | 29 | public String getHostname() { 30 | return hostname; 31 | } 32 | 33 | public void setHostname(final String hostname) { 34 | this.hostname = hostname; 35 | } 36 | 37 | public String getZosmfport() { 38 | return zosmfPort; 39 | } 40 | 41 | public void setZosmfport(final String zosmfPort) { 42 | this.zosmfPort = zosmfPort; 43 | } 44 | 45 | public String getSshport() { 46 | return sshport; 47 | } 48 | 49 | public void setSshport(final String sshport) { 50 | this.sshport = sshport; 51 | } 52 | 53 | public String getUsername() { 54 | return username; 55 | } 56 | 57 | public void setUsername(final String username) { 58 | this.username = username; 59 | } 60 | 61 | public String getPassword() { 62 | return password; 63 | } 64 | 65 | public void setPassword(final String password) { 66 | this.password = password; 67 | } 68 | 69 | public String getDownloadpath() { 70 | return downloadPath; 71 | } 72 | 73 | public void setDownloadpath(final String downloadPath) { 74 | this.downloadPath = downloadPath; 75 | } 76 | 77 | public String getConsolename() { 78 | return consoleName; 79 | } 80 | 81 | public void setConsolename(final String consolename) { 82 | this.consoleName = consolename; 83 | } 84 | 85 | public String getAccountnumber() { 86 | return accountNumber; 87 | } 88 | 89 | public void setAccountnumber(final String accountnumber) { 90 | this.accountNumber = accountnumber; 91 | } 92 | 93 | public String getBrowselimit() { 94 | return browseLimit; 95 | } 96 | 97 | public void setBrowselimit(String browselimit) { 98 | this.browseLimit = browselimit; 99 | } 100 | 101 | public String getPrompt() { 102 | return prompt; 103 | } 104 | 105 | public void setPrompt(String prompt) { 106 | this.prompt = prompt; 107 | } 108 | 109 | public Window getWindow() { 110 | return window; 111 | } 112 | 113 | public void setWindow(final Window window) { 114 | this.window = window; 115 | } 116 | 117 | @Override 118 | public String toString() { 119 | return "Profile{" + 120 | "name='" + name + '\'' + 121 | ", hostname='" + hostname + '\'' + 122 | ", zosmfPort='" + zosmfPort + '\'' + 123 | ", sshport='" + sshport + '\'' + 124 | ", username='" + username + '\'' + 125 | ", password='" + password + '\'' + 126 | ", downloadPath='" + downloadPath + '\'' + 127 | ", consoleName='" + consoleName + '\'' + 128 | ", accountNumber='" + accountNumber + '\'' + 129 | ", browseLimit='" + browseLimit + '\'' + 130 | ", prompt='" + prompt + '\'' + 131 | ", window=" + window + 132 | '}'; 133 | } 134 | 135 | } 136 | 137 | 138 | -------------------------------------------------------------------------------- /src/main/java/zos/shell/singleton/configuration/model/Window.java: -------------------------------------------------------------------------------- 1 | package zos.shell.singleton.configuration.model; 2 | 3 | public class Window { 4 | 5 | private String fontsize; 6 | private String fontBold; 7 | private String textColor; 8 | private String backGroundColor; 9 | private String paneHeight; 10 | private String paneWidth; 11 | 12 | public String getFontsize() { 13 | return fontsize; 14 | } 15 | 16 | public void setFontsize(final String fontsize) { 17 | this.fontsize = fontsize; 18 | } 19 | 20 | public String getFontbold() { 21 | return fontBold; 22 | } 23 | 24 | public void setFontbold(final String fontbold) { 25 | this.fontBold = fontbold; 26 | } 27 | 28 | public String getTextcolor() { 29 | return textColor; 30 | } 31 | 32 | public void setTextcolor(final String textColor) { 33 | this.textColor = textColor; 34 | } 35 | 36 | public String getBackgroundcolor() { 37 | return backGroundColor; 38 | } 39 | 40 | public void setBackgroundcolor(final String backGroundColor) { 41 | this.backGroundColor = backGroundColor; 42 | } 43 | 44 | public String getPaneHeight() { 45 | return paneHeight; 46 | } 47 | 48 | public void setPaneHeight(String paneHeight) { 49 | this.paneHeight = paneHeight; 50 | } 51 | 52 | public String getPaneWidth() { 53 | return paneWidth; 54 | } 55 | 56 | public void setPaneWidth(String paneWidth) { 57 | this.paneWidth = paneWidth; 58 | } 59 | 60 | @Override 61 | public String toString() { 62 | return "Window{" + 63 | "fontsize='" + fontsize + '\'' + 64 | ", fontBold='" + fontBold + '\'' + 65 | ", textColor='" + textColor + '\'' + 66 | ", backGroundColor='" + backGroundColor + '\'' + 67 | ", paneHeight='" + paneHeight + '\'' + 68 | ", paneWidth='" + paneWidth + '\'' + 69 | '}'; 70 | } 71 | 72 | } 73 | -------------------------------------------------------------------------------- /src/main/java/zos/shell/singleton/configuration/record/ConfigSettings.java: -------------------------------------------------------------------------------- 1 | package zos.shell.singleton.configuration.record; 2 | 3 | import zos.shell.singleton.EnvVariableSingleton; 4 | import zos.shell.singleton.configuration.model.Window; 5 | 6 | public class ConfigSettings { 7 | 8 | private final String hostName; 9 | private final String downloadPath; 10 | private final String consoleName; 11 | private final String accountNumber; 12 | private final String browseLimit; 13 | private final String prompt; 14 | private final Window window; 15 | 16 | public ConfigSettings(final String hostName, final String downloadPath, final String consoleName, 17 | final String accountNumber, final String browseLimit, final String prompt, 18 | final Window window) { 19 | this.hostName = hostName; 20 | if (hostName != null && !hostName.isBlank()) { 21 | EnvVariableSingleton.getInstance().getVariables().put("HOSTNAME", hostName); 22 | } 23 | this.downloadPath = downloadPath; 24 | if (downloadPath != null && !downloadPath.isBlank()) { 25 | EnvVariableSingleton.getInstance().getVariables().put("DOWNLOAD_PATH", downloadPath); 26 | } 27 | this.consoleName = consoleName; 28 | if (consoleName != null && !consoleName.isBlank()) { 29 | EnvVariableSingleton.getInstance().getVariables().put("CONSOLE_NAME", consoleName); 30 | } 31 | this.accountNumber = accountNumber; 32 | if (accountNumber != null && !accountNumber.isBlank()) { 33 | EnvVariableSingleton.getInstance().getVariables().put("ACCOUNT_NUMBER", accountNumber); 34 | } 35 | this.browseLimit = browseLimit; 36 | if (browseLimit != null && !browseLimit.isBlank()) { 37 | EnvVariableSingleton.getInstance().getVariables().put("BROWSE_LIMIT", browseLimit); 38 | } 39 | this.prompt = prompt; 40 | if (prompt != null && !prompt.isBlank()) { 41 | EnvVariableSingleton.getInstance().getVariables().put("PROMPT", prompt); 42 | } 43 | this.window = window; 44 | } 45 | 46 | public String getHostName() { 47 | return hostName; 48 | } 49 | 50 | public String getDownloadPath() { 51 | return downloadPath; 52 | } 53 | 54 | public String getConsoleName() { 55 | return consoleName; 56 | } 57 | 58 | public String getAccountNumber() { 59 | return accountNumber; 60 | } 61 | 62 | public String getBrowseLimit() { 63 | return browseLimit; 64 | } 65 | 66 | public String getPrompt() { 67 | return prompt; 68 | } 69 | 70 | public Window getWindow() { 71 | return window; 72 | } 73 | 74 | @Override 75 | public String toString() { 76 | return "ConfigSettings{" + 77 | "hostName='" + hostName + '\'' + 78 | ", downloadPath='" + downloadPath + '\'' + 79 | ", consoleName='" + consoleName + '\'' + 80 | ", accountNumber='" + accountNumber + '\'' + 81 | ", browseLimit='" + browseLimit + '\'' + 82 | ", prompt='" + prompt + '\'' + 83 | ", window=" + window + 84 | '}'; 85 | } 86 | 87 | } 88 | -------------------------------------------------------------------------------- /src/main/java/zos/shell/utility/DsnUtil.java: -------------------------------------------------------------------------------- 1 | package zos.shell.utility; 2 | 3 | import org.slf4j.Logger; 4 | import org.slf4j.LoggerFactory; 5 | import zowe.client.sdk.zosfiles.dsn.response.Member; 6 | 7 | import java.util.List; 8 | import java.util.Locale; 9 | import java.util.function.Predicate; 10 | import java.util.regex.Pattern; 11 | import java.util.stream.Collectors; 12 | 13 | public class DsnUtil { 14 | 15 | private DsnUtil() { 16 | throw new IllegalStateException("Utility class"); 17 | } 18 | 19 | private static final Logger LOG = LoggerFactory.getLogger(DsnUtil.class); 20 | 21 | private static final String PATTERN_STRING_MORE_THAN_ONE_CHAR = "[A-Z#@\\$][A-Z\\d#@\\$\\-]{1,7}"; 22 | private static final String PATTERN_STRING_FOR_ONE_CHAR = "[A-Z#@\\$]{1}"; 23 | 24 | public static boolean isDataset(String name) { 25 | LOG.debug("*** isDataset ***"); 26 | name = name.toUpperCase(Locale.ROOT); 27 | 28 | // Check that the dataset contains more than one segment 29 | // This could be valid for additionalTests 30 | var segments = name.split("\\."); 31 | if (segments.length < 2) { 32 | return false; 33 | } 34 | 35 | // The length cannot be longer than 44 36 | if (name.length() > 44) { 37 | return false; 38 | } 39 | 40 | // The name cannot contain two successive periods 41 | if (name.contains("..")) { 42 | return false; 43 | } 44 | 45 | // Cannot end in a period 46 | if (name.endsWith(".")) { 47 | return false; 48 | } 49 | 50 | for (var segment : segments) { 51 | if (!isSegment(segment)) { 52 | return false; 53 | } 54 | } 55 | 56 | return true; 57 | } 58 | 59 | public static boolean isMember(final String name) { 60 | LOG.debug("*** isMember ***"); 61 | return isSegment(name.toUpperCase(Locale.ROOT)); 62 | } 63 | 64 | private static boolean isSegment(final String segment) { 65 | LOG.debug("*** isSegment ***"); 66 | // Each segment cannot be more than 8 characters 67 | // Each segment's first letter is a letter or #, @, $. 68 | // The remaining seven characters in a segment can be letters, numbers, and #, @, $, - 69 | var size = segment.length(); 70 | if (size > 8) { 71 | return false; 72 | } 73 | 74 | if (size == 1) { 75 | var p = Pattern.compile(PATTERN_STRING_FOR_ONE_CHAR); 76 | var m = p.matcher(segment); 77 | return m.matches(); 78 | } 79 | 80 | var p = Pattern.compile(PATTERN_STRING_MORE_THAN_ONE_CHAR); 81 | var m = p.matcher(segment); 82 | return m.matches(); 83 | } 84 | 85 | public static List getMembersByFilter(final String filter, final List members) { 86 | LOG.debug("*** getMembersByFilter ***"); 87 | Predicate isMemberPresent = m -> m.getMember().isPresent(); 88 | Predicate isMemberFound = m -> m.getMember().orElse("").equalsIgnoreCase(filter.toUpperCase()); 89 | return members.stream().filter(isMemberPresent.and(isMemberFound)).collect(Collectors.toList()); 90 | } 91 | 92 | public static List getMembersByStartsWithFilter(final String filter, final List members) { 93 | LOG.debug("*** getMembersByStartsWithFilter ***"); 94 | Predicate isMemberPresent = m -> m.getMember().isPresent(); 95 | Predicate isMemberFound = m -> m.getMember().orElse("").startsWith(filter.toUpperCase()); 96 | return members.stream().filter(isMemberPresent.and(isMemberFound)).collect(Collectors.toList()); 97 | } 98 | 99 | } 100 | -------------------------------------------------------------------------------- /src/main/java/zos/shell/utility/FileUtil.java: -------------------------------------------------------------------------------- 1 | package zos.shell.utility; 2 | 3 | import org.apache.commons.io.FileUtils; 4 | import org.apache.commons.io.IOUtils; 5 | import org.apache.commons.lang3.SystemUtils; 6 | import org.slf4j.Logger; 7 | import org.slf4j.LoggerFactory; 8 | import zos.shell.constants.Constants; 9 | 10 | import java.io.File; 11 | import java.io.IOException; 12 | import java.io.InputStream; 13 | import java.io.StringWriter; 14 | import java.nio.file.Files; 15 | import java.nio.file.Paths; 16 | 17 | public final class FileUtil { 18 | 19 | private static final Logger LOG = LoggerFactory.getLogger(FileUtil.class); 20 | 21 | private FileUtil() { 22 | throw new IllegalStateException("Utility class"); 23 | } 24 | 25 | public static void openFileLocation(final String filePath) { 26 | LOG.debug("*** openFileLocation ***"); 27 | if (filePath == null) { 28 | return; 29 | } 30 | 31 | var file = new File(filePath); 32 | try { 33 | LOG.info("canonical path {}", file.getCanonicalPath()); 34 | if (SystemUtils.IS_OS_WINDOWS) { 35 | // open directory in explorer 36 | Runtime.getRuntime().exec("explorer.exe /select, " + file.getCanonicalPath()); 37 | } else if (SystemUtils.IS_OS_MAC_OSX) { 38 | var arr = file.getCanonicalPath().split("/"); 39 | var str = new StringBuilder(); 40 | if (file.isDirectory()) { 41 | str.append(file.getCanonicalPath()); 42 | } else { // is file, remove the file name and open directory only 43 | for (var i = 0; i < arr.length - 1; i++) { 44 | str.append(arr[i]).append("/"); 45 | } 46 | } 47 | Runtime.getRuntime().exec("/usr/bin/open " + str); 48 | } 49 | } catch (IOException ignored) { 50 | } 51 | } 52 | 53 | public static void writeTextFile(final String content, final String directoryPath, 54 | final String fileNamePath) throws IOException { 55 | LOG.debug("*** writeTextFile ***"); 56 | Files.createDirectories(Paths.get(directoryPath)); 57 | Files.write(Paths.get(fileNamePath), content.getBytes()); 58 | } 59 | 60 | public static void writeBinaryFile(final InputStream input, final String directoryPath, 61 | final String fileNamePath) throws IOException { 62 | LOG.debug("*** writeBinaryFile ***"); 63 | Files.createDirectories(Paths.get(directoryPath)); 64 | FileUtils.copyInputStreamToFile(input, new File(fileNamePath)); 65 | } 66 | 67 | public static String getTextStreamData(final InputStream inputStream) throws IOException { 68 | LOG.debug("*** getTextStreamData ***"); 69 | if (inputStream != null) { 70 | var writer = new StringWriter(); 71 | IOUtils.copy(inputStream, writer, Constants.UTF8); 72 | inputStream.close(); 73 | return writer.toString(); 74 | } 75 | return null; 76 | } 77 | 78 | } 79 | -------------------------------------------------------------------------------- /src/main/java/zos/shell/utility/FutureUtil.java: -------------------------------------------------------------------------------- 1 | package zos.shell.utility; 2 | 3 | import com.google.common.base.Strings; 4 | import org.slf4j.Logger; 5 | import org.slf4j.LoggerFactory; 6 | import zos.shell.constants.Constants; 7 | import zos.shell.response.ResponseStatus; 8 | 9 | import java.util.List; 10 | import java.util.concurrent.*; 11 | 12 | public final class FutureUtil { 13 | 14 | private static final Logger LOG = LoggerFactory.getLogger(FutureUtil.class); 15 | 16 | private FutureUtil() { 17 | throw new IllegalStateException("Utility class"); 18 | } 19 | 20 | public static ResponseStatus getFutureResponse(final Future future, final ExecutorService pool, 21 | final long timeout) { 22 | LOG.debug("*** getFutureResponse ***"); 23 | try { 24 | return future.get(timeout, TimeUnit.SECONDS); 25 | } catch (InterruptedException | ExecutionException e) { 26 | LOG.debug("exception error: {}", String.valueOf(e)); 27 | future.cancel(true); 28 | boolean isErrMsg = e.getMessage() != null && !e.getMessage().isBlank(); 29 | var errMsg = isErrMsg ? e.getMessage() : Constants.COMMAND_EXECUTION_ERROR_MSG; 30 | return new ResponseStatus(errMsg, false); 31 | } catch (TimeoutException e) { 32 | future.cancel(true); 33 | return new ResponseStatus(Constants.TIMEOUT_MESSAGE, false); 34 | } finally { 35 | pool.shutdown(); 36 | } 37 | } 38 | 39 | public static ResponseStatus getFutureResponses(final List> futures, 40 | final ExecutorService pool, final long timeout, 41 | final int padLength) { 42 | LOG.debug("*** getFutureResponses ***"); 43 | var results = new StringBuilder(); 44 | futures.forEach(future -> { 45 | ResponseStatus responseStatus; 46 | try { 47 | responseStatus = future.get(timeout, TimeUnit.SECONDS); 48 | var arrowMsg = Strings.padStart(responseStatus.getOptionalData(), padLength, ' '); 49 | arrowMsg += Constants.ARROW; 50 | results.append(arrowMsg).append(responseStatus.getMessage()).append("\n"); 51 | } catch (InterruptedException | ExecutionException e) { 52 | LOG.debug("exception error: {}", String.valueOf(e)); 53 | future.cancel(true); 54 | var isErrMsg = e.getMessage() != null && !e.getMessage().isBlank(); 55 | var errMsg = isErrMsg ? e.getMessage() : Constants.COMMAND_EXECUTION_ERROR_MSG; 56 | results.append(errMsg).append("\n"); 57 | } catch (TimeoutException e) { 58 | future.cancel(true); 59 | results.append(Constants.TIMEOUT_MESSAGE).append("\n"); 60 | } 61 | }); 62 | 63 | pool.shutdown(); 64 | return new ResponseStatus(results.toString(), true); 65 | } 66 | 67 | } 68 | -------------------------------------------------------------------------------- /src/main/java/zos/shell/utility/PromptUtil.java: -------------------------------------------------------------------------------- 1 | package zos.shell.utility; 2 | 3 | import org.slf4j.Logger; 4 | import org.slf4j.LoggerFactory; 5 | import zos.shell.constants.Constants; 6 | import zos.shell.controller.container.ControllerFactoryContainer; 7 | import zos.shell.singleton.TerminalSingleton; 8 | 9 | public final class PromptUtil { 10 | 11 | private static final Logger LOG = LoggerFactory.getLogger(PromptUtil.class); 12 | 13 | private PromptUtil() { 14 | throw new IllegalStateException("Utility class"); 15 | } 16 | 17 | @SuppressWarnings("SameReturnValue") 18 | public static String getPrompt() { 19 | LOG.debug("*** getPrompt ***"); 20 | var controllerFactoryContainer = new ControllerFactoryContainer(); 21 | var envVariableController = controllerFactoryContainer.getEnvVariableController(); 22 | var promptStr = envVariableController.getValueByEnv("PROMPT"); 23 | if (promptStr != null && !promptStr.isBlank()) { 24 | int startIndex = promptStr.indexOf("$("); 25 | if (startIndex != -1) { 26 | int endIndex = promptStr.indexOf(")"); 27 | if (endIndex != 1) { 28 | var valueStr = promptStr.substring(startIndex + 2, endIndex); 29 | var replacePromptStr = envVariableController.getValueByEnv(valueStr.trim()); 30 | if (replacePromptStr != null && !replacePromptStr.isBlank()) { 31 | promptStr = promptStr.replace("$(" + valueStr + ")", replacePromptStr); 32 | } 33 | } 34 | } 35 | return promptStr + Constants.DEFAULT_PROMPT; 36 | } 37 | return Constants.DEFAULT_PROMPT; 38 | } 39 | 40 | public static String getPromptInfo(final String promptMsg, final boolean isMask) { 41 | LOG.debug("*** getPromptInfo ***"); 42 | TerminalSingleton.getInstance().setDisableKeys(true); 43 | var result = TerminalSingleton.getInstance() 44 | .getMainTextIO() 45 | .newStringInputReader() 46 | .withMaxLength(80) 47 | .withInputMasking(isMask) 48 | .read(promptMsg); 49 | TerminalSingleton.getInstance().setDisableKeys(false); 50 | return result; 51 | } 52 | 53 | } 54 | -------------------------------------------------------------------------------- /src/main/java/zos/shell/utility/ResponseUtil.java: -------------------------------------------------------------------------------- 1 | package zos.shell.utility; 2 | 3 | import org.slf4j.Logger; 4 | import org.slf4j.LoggerFactory; 5 | import zos.shell.constants.Constants; 6 | import zos.shell.response.ResponseStatus; 7 | import zowe.client.sdk.rest.Response; 8 | import zowe.client.sdk.rest.exception.ZosmfRequestException; 9 | 10 | import java.io.ByteArrayInputStream; 11 | import java.io.IOException; 12 | 13 | public final class ResponseUtil { 14 | 15 | private static final Logger LOG = LoggerFactory.getLogger(ResponseUtil.class); 16 | 17 | private ResponseUtil() { 18 | throw new IllegalStateException("Utility class"); 19 | } 20 | 21 | public static ResponseStatus getByteResponseStatus(ZosmfRequestException e) { 22 | LOG.debug("*** getByteResponseStatus ***"); 23 | var byteMsg = (byte[]) e.getResponse().getResponsePhrase().get(); 24 | var errorStream = new ByteArrayInputStream(byteMsg); 25 | String errMsg; 26 | try { 27 | errMsg = FileUtil.getTextStreamData(errorStream); 28 | if (errMsg == null) { 29 | errMsg = ""; 30 | } 31 | } catch (IOException ex) { 32 | errMsg = "error processing response"; 33 | } 34 | return new ResponseStatus(errMsg.isBlank() ? e.getMessage() : errMsg, false); 35 | } 36 | 37 | public static String getResponsePhrase(final Response response) { 38 | LOG.debug("*** getResponsePhrase ***"); 39 | if (response == null || response.getResponsePhrase().isEmpty()) { 40 | return null; 41 | } 42 | return response.getResponsePhrase().get().toString(); 43 | } 44 | 45 | public static String getMsgAfterArrow(final String msg) { 46 | LOG.debug("*** getMsgAfterArrow ***"); 47 | if (!msg.contains(Constants.ARROW)) { 48 | return msg; 49 | } 50 | int index = msg.indexOf(Constants.ARROW) + Constants.ARROW.length(); 51 | return msg.substring(index); 52 | } 53 | 54 | } 55 | -------------------------------------------------------------------------------- /src/main/java/zos/shell/utility/StrUtil.java: -------------------------------------------------------------------------------- 1 | package zos.shell.utility; 2 | 3 | import org.slf4j.Logger; 4 | import org.slf4j.LoggerFactory; 5 | 6 | import java.util.ArrayList; 7 | import java.util.Arrays; 8 | import java.util.Collections; 9 | 10 | public final class StrUtil { 11 | 12 | private static final Logger LOG = LoggerFactory.getLogger(StrUtil.class); 13 | 14 | private StrUtil() { 15 | throw new IllegalStateException("Utility class"); 16 | } 17 | 18 | public static boolean isStrNum(final String str) { 19 | LOG.debug("*** isStrNum ***"); 20 | try { 21 | Integer.parseInt(str); 22 | return true; 23 | } catch (NumberFormatException nfe) { 24 | return false; 25 | } 26 | } 27 | 28 | public static String[] stripEmptyStrings(String[] command) { 29 | LOG.debug("*** stripEmptyStrings ***"); 30 | // handle multiple empty spaces specified 31 | if (Arrays.stream(command).anyMatch(String::isEmpty)) { 32 | var list = new ArrayList<>(Arrays.asList(command)); 33 | list.removeAll(Collections.singleton("")); 34 | command = list.toArray(new String[0]); 35 | return command; 36 | } 37 | return command; 38 | } 39 | 40 | } 41 | -------------------------------------------------------------------------------- /src/main/resources/image/zowe-icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Zowe-Java-SDK/ZosShell/18d80f416b700725aaeb73e160f7562cae4939c4/src/main/resources/image/zowe-icon.png -------------------------------------------------------------------------------- /src/main/resources/logback.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | %d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n 5 | 6 | 7 | 8 | 9 | 10 | 11 | --------------------------------------------------------------------------------