public void export(Path file) throws Exception { ProvisioningXmlWriter.getInstance().write(config, file); }
@Override protected void runCommand(PmCommandInvocation invoc) throws CommandExecutionException { if (file != null) { final Path targetFile = file.toPath(); try { getManager(invoc.getPmSession()).exportProvisioningConfig(targetFile); } catch (ProvisioningException | IOException e) { throw new CommandExecutionException(invoc.getPmSession(), CliErrors.exportProvisionedFailed(), e); } invoc.println("Provisioning file generated in " + targetFile); } else { ByteArrayOutputStream output = null; try { ProvisioningConfig config = getManager(invoc.getPmSession()).getProvisioningConfig(); output = new ByteArrayOutputStream(); PrintWriter writer = new PrintWriter(new OutputStreamWriter(output, StandardCharsets.UTF_8)); ProvisioningXmlWriter.getInstance().write(config, writer); } catch (Exception e) { throw new CommandExecutionException(invoc.getPmSession(), CliErrors.exportProvisionedFailed(), e); } try { invoc.println(output.toString(StandardCharsets.UTF_8.name())); } catch (UnsupportedEncodingException e) { throw new CommandExecutionException(invoc.getPmSession(), CliErrors.exportProvisionedFailed(), e); } } }
@Override protected void runCommand(PmCommandInvocation invoc) throws CommandExecutionException { if (file != null) { final Path targetFile = file.toPath(); State session = invoc.getPmSession().getState(); try { session.export(targetFile); } catch (Exception ex) { throw new CommandExecutionException(invoc.getPmSession(), CliErrors.exportProvisionedFailed(), ex); } invoc.println("Provisioning file generated in " + targetFile); } else { ByteArrayOutputStream output = null; try { ProvisioningConfig config = invoc.getPmSession().getState().getConfig(); output = new ByteArrayOutputStream(); PrintWriter writer = new PrintWriter(new OutputStreamWriter(output, StandardCharsets.UTF_8)); ProvisioningXmlWriter.getInstance().write(config, writer); } catch (Exception e) { throw new CommandExecutionException(invoc.getPmSession(), CliErrors.exportProvisionedFailed(), e); } try { invoc.println(output.toString(StandardCharsets.UTF_8.name())); } catch (UnsupportedEncodingException e) { throw new CommandExecutionException(invoc.getPmSession(), CliErrors.exportProvisionedFailed(), e); } } }
/** * Add named universe spec to the provisioning configuration * * @param name universe name * @param universeSpec universe spec * @throws ProvisioningException in case of an error */ public void addUniverse(String name, UniverseSpec universeSpec) throws ProvisioningException { final ProvisioningConfig config = ProvisioningConfig.builder(getProvisioningConfig()).addUniverse(name, universeSpec).build(); try { ProvisioningXmlWriter.getInstance().write(config, PathsUtils.getProvisioningXml(home)); } catch (Exception e) { throw new ProvisioningException(Errors.writeFile(PathsUtils.getProvisioningXml(home)), e); } this.provisioningConfig = config; }
/** * Removes universe spec associated with the name from the provisioning configuration * @param name name of the universe spec or null for the default universe spec * @throws ProvisioningException in case of an error */ public void removeUniverse(String name) throws ProvisioningException { ProvisioningConfig config = getProvisioningConfig(); if(config == null || !config.hasUniverse(name)) { return; } config = ProvisioningConfig.builder(config).removeUniverse(name).build(); try { ProvisioningXmlWriter.getInstance().write(config, PathsUtils.getProvisioningXml(home)); } catch (Exception e) { throw new ProvisioningException(Errors.writeFile(PathsUtils.getProvisioningXml(home)), e); } this.provisioningConfig = config; }
ProvisioningXmlWriter.getInstance().write(config, PathsUtils.getProvisioningXml(stagedDir)); } catch (XMLStreamException | IOException e) { throw new FeaturePackInstallException(Errors.writeFile(PathsUtils.getProvisioningXml(stagedDir)), e);