# Slice Command ## Overview The `slice` command extracts specific sections (entity types) from a Gateway configuration bundle, creating a new bundle with only the selected entities. This is useful for creating focused bundles, removing unwanted entities, or preparing selective deployments. ## Syntax ```bash graphman slice --input [--sections
...] [--output ] [--filter.
. [.]] ``` ## Parameters ### Required Parameters | Parameter | Description | |-----------|-------------| | `--input` | Input bundle file to slice | ### Optional Parameters | Parameter | Description | Default | |-----------|-------------|---------| | `--sections` | One or more section names to include/exclude | None (empty bundle) | | `--output` | Output file for the sliced bundle | Standard output (console) | | `--filter.
.` | Filter entities within sections | None | ## Section Specification Sections refer to entity types using their **plural names**: | Section Name | Entity Type | |--------------|-------------| | `services` | Web Services | | `policies` | Policies | | `policyFragments` | Policy Fragments | | `folders` | Folders | | `keys` | Private Keys | | `trustedCerts` | Trusted Certificates | | `jdbcConnections` | JDBC Connections | | `jmsDestinations` | JMS Destinations | | `clusterProperties` | Cluster Properties | | `scheduledTasks` | Scheduled Tasks | | `encassConfigs` | Encapsulated Assertions | ### Special Section Names | Section | Meaning | |---------|---------| | `*` | All sections in the bundle | | `-
` | Exclude the specified section | | `+
` | Explicitly include the section (optional prefix) | ## Behavior ### Inclusion Logic 1. Sections are processed in the order specified 2. Use `*` to include all sections first 3. Use `-section` to exclude specific sections 4. Sections not listed are excluded by default ### Filter Application - Filters are applied after section selection - Filters use the same syntax as the export command - Multiple filters are combined with AND logic ## Examples ### Extract Specific Sections Extract only services and policies: ```bash graphman slice --input full-bundle.json --sections services policies --output services-policies.json ``` ### Extract All Except Specific Sections Include everything except folders and cluster properties: ```bash graphman slice --input bundle.json --sections "*" -folders -clusterProperties --output filtered.json ``` ### Extract Single Section Extract only services: ```bash graphman slice --input bundle.json --sections services --output services-only.json ``` ### Extract with Filters Extract services in a specific folder: ```bash graphman slice --input bundle.json --sections services \ --filter.services.folderPath.eq /APIs/External \ --output external-apis.json ``` Extract enabled services only: ```bash graphman slice --input bundle.json --sections services \ --filter.services.enabled.eq true \ --output enabled-services.json ``` ### Complex Section Selection Include all, then exclude several sections: ```bash graphman slice --input bundle.json \ --sections "*" -scheduledTasks -auditConfigurations -emailListeners \ --output deployment-bundle.json ``` ### Multiple Filters Combine multiple filter criteria: ```bash graphman slice --input bundle.json --sections services \ --filter.services.enabled.eq true \ --filter.services.folderPath.regex "^/Production" \ --output prod-enabled-services.json ``` ## Use Cases ### 1. Selective Deployment Deploy only specific entity types: ```bash # Extract services and policies for deployment graphman slice --input full-config.json --sections services policies --output deployment.json graphman import --input deployment.json --gateway prod ``` ### 2. Remove Sensitive Data Remove keys and certificates before sharing: ```bash graphman slice --input bundle.json \ --sections "*" -keys -trustedCerts -passwords \ --output shareable-config.json ``` ### 3. Environment-Specific Configuration Extract environment-specific entities: ```bash graphman slice --input bundle.json \ --sections clusterProperties jdbcConnections jmsDestinations \ --output env-config.json ``` ### 4. Policy Library Extract reusable policies and fragments: ```bash graphman slice --input bundle.json \ --sections policies policyFragments \ --filter.policies.folderPath.eq /Library \ --output policy-library.json ``` ### 5. Incremental Deployment Deploy entities in stages: ```bash # Stage 1: Infrastructure graphman slice --input bundle.json --sections folders clusterProperties --output stage1.json # Stage 2: Security graphman slice --input bundle.json --sections keys trustedCerts --output stage2.json # Stage 3: Services graphman slice --input bundle.json --sections services policies --output stage3.json ``` ### 6. Cleanup Preparation Identify entities for deletion: ```bash graphman slice --input current-config.json \ --sections services \ --filter.services.folderPath.eq /Deprecated \ --output to-delete.json ``` ### 7. Configuration Comparison Extract comparable sections from different environments: ```bash graphman slice --input dev-config.json --sections services policies --output dev-services.json graphman slice --input prod-config.json --sections services policies --output prod-services.json graphman diff --input-source dev-services.json --input-target prod-services.json --output differences.json ``` ## Filter Matching Criteria | Criteria | Description | Example | |----------|-------------|---------| | `eq`, `equals` | Exact match (default) | `--filter.services.name.eq MyService` | | `neq` | Not equals | `--filter.services.enabled.neq false` | | `regex` | Regular expression | `--filter.services.name.regex ^API.*` | | `gt` | Greater than | `--filter.services.version.gt 5` | | `lt` | Less than | `--filter.services.version.lt 10` | | `gte` | Greater than or equals | `--filter.services.version.gte 1` | | `lte` | Less than or equals | `--filter.services.version.lte 5` | ## Advanced Usage ### Combining Sections and Filters Extract specific services and all their dependencies: ```bash # First, export with dependencies graphman export --using services --variables.name "MyService" \ --options.excludeDependencies false --gateway prod --output with-deps.json # Then slice to remove unwanted sections graphman slice --input with-deps.json \ --sections services policies folders keys \ --output deployment-ready.json ``` ### Global Filters Apply filters across all sections: ```bash graphman slice --input bundle.json --sections "*" \ --filter.*.folderPath.regex "^/Production" \ --output production-entities.json ``` ### Section-Specific Filters Different filters for different sections: ```bash graphman slice --input bundle.json \ --sections services policies \ --filter.services.enabled.eq true \ --filter.policies.policyType.eq "Include" \ --output filtered.json ``` ## Important Notes - Section names are case-sensitive and must use plural form - Unknown section names generate warnings but don't cause errors - Empty sections are included in output (as empty arrays) - The output bundle is automatically sorted - Filters are applied after section selection - Use `schema` command to see all available section names - Bundle properties are preserved in the output - The `*` section must be specified first if used with exclusions ## Section Order Sections appear in the output in the standard order: 1. Entity sections (alphabetically by plural name) 2. Bundle properties (always last) ## Related Commands - **[combine](Combine-Command.md)**: Merge multiple bundles - **[export](Export-Command.md)**: Export with built-in filtering - **[diff](Diff-Command.md)**: Compare sliced bundles - **[explode](Explode-Command.md)**: Break down sliced bundles ## Best Practices 1. **Use descriptive output names** that indicate what was sliced 2. **Validate sliced bundles** before importing 3. **Document section selections** in deployment procedures 4. **Test sliced bundles** in non-production first 5. **Combine with filters** for precise entity selection 6. **Use `*` with exclusions** to simplify complex selections 7. **Check section names** using the `schema` command 8. **Preserve dependencies** when slicing for deployment ## Workflow Examples ### Deployment Pipeline ```bash #!/bin/bash # Export from development graphman export --gateway dev --output dev-full.json # Slice for production deployment graphman slice --input dev-full.json \ --sections services policies folders \ --filter.services.folderPath.regex "^/Release" \ --output prod-deployment.json # Validate graphman validate --input prod-deployment.json # Deploy graphman import --input prod-deployment.json --gateway prod ``` ### Configuration Backup Strategy ```bash #!/bin/bash DATE=$(date +%Y%m%d) # Full backup graphman export --gateway prod --output backups/full-$DATE.json # Security backup graphman slice --input backups/full-$DATE.json \ --sections keys trustedCerts \ --output backups/security-$DATE.json # Services backup graphman slice --input backups/full-$DATE.json \ --sections services policies policyFragments \ --output backups/services-$DATE.json ``` ## Troubleshooting ### Unknown Section Warning ``` warn: unknown section mySection ``` **Solution**: Check section name spelling and use plural form. Use `graphman schema` to list valid sections. ### Empty Output If output is empty, ensure: - Section names are correct - Sections exist in the input bundle - Filters aren't too restrictive ### Filter Not Working Verify: - Filter syntax: `--filter.
.. ` - Field names match entity structure - Matching criteria is valid