Thanks to visit codestin.com
Credit goes to Github.com

Skip to content

πŸš€ Production-ready MuleSoft API-led architecture for Oil & Gas field service operations integrating Salesforce Agentforce, ServiceNow, SAP S/4HANA, and Contract Management systems

License

Notifications You must be signed in to change notification settings

msaleme/energy-field-service-integration

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

2 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Energy Field Service Integration Platform

A comprehensive API-led MuleSoft architecture for Oil & Gas field service operations integrating Salesforce Agentforce, ServiceNow, SAP S/4HANA, and Contract Management systems.

Architecture Overview

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                        EXPERIENCE LAYER                         β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚  experience-energy-ops-api                                     β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”   β”‚
β”‚  β”‚ Work Orders     β”‚ β”‚ Asset Context   β”‚ β”‚ Dispatch &      β”‚   β”‚
β”‚  β”‚ β€’ Create        β”‚ β”‚ β€’ Lookup        β”‚ β”‚ Estimates       β”‚   β”‚
β”‚  β”‚ β€’ Update        β”‚ β”‚ β€’ Cache         β”‚ β”‚ β€’ Approval      β”‚   β”‚
β”‚  β”‚ β€’ List/Get      β”‚ β”‚ β€’ Contracts     β”‚ β”‚ β€’ Assignment    β”‚   β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜   β”‚
β”‚  OAuth 2.0 | JWT | Rate Limiting | OWASP Policies | mTLS       β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                                β”‚
                                β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                        PROCESS LAYER                            β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚  process-field-service-orch-api                               β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”   β”‚
β”‚  β”‚ Work Order      β”‚ β”‚ Asset Master    β”‚ β”‚ Contract        β”‚   β”‚
β”‚  β”‚ Orchestration   β”‚ β”‚ Sync            β”‚ β”‚ Resolution      β”‚   β”‚
β”‚  β”‚ β€’ Saga Pattern  β”‚ β”‚ β€’ Delta Sync    β”‚ β”‚ β€’ Rate Cards    β”‚   β”‚
β”‚  β”‚ β€’ Compensation  β”‚ β”‚ β€’ Cache Refresh β”‚ β”‚ β€’ SLA Terms     β”‚   β”‚
β”‚  β”‚ β€’ Retry/Circuit β”‚ β”‚ β€’ Batch Process β”‚ β”‚ β€’ Geo Matching  β”‚   β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜   β”‚
β”‚  Anypoint MQ | Event Streaming | Error Handling | Monitoring   β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                                β”‚
           β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
           β–Ό                    β–Ό                    β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚   SYSTEM LAYER    β”‚ β”‚   SYSTEM LAYER    β”‚ β”‚   SYSTEM LAYER    β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€ β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€ β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚system-sap-eam-api β”‚ β”‚system-servicenow  β”‚ β”‚ system-clm-api    β”‚
β”‚                   β”‚ β”‚     -api          β”‚ β”‚                   β”‚
β”‚ β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚ β”‚ β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚ β”‚ β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚
β”‚ β”‚ Asset Master  β”‚ β”‚ β”‚ β”‚ Work Orders   β”‚ β”‚ β”‚ β”‚ Contracts     β”‚ β”‚
β”‚ β”‚ Maintenance   β”‚ β”‚ β”‚ β”‚ ITSM/Field    β”‚ β”‚ β”‚ β”‚ Rate Cards    β”‚ β”‚
β”‚ β”‚ Notifications β”‚ β”‚ β”‚ β”‚ Technicians   β”‚ β”‚ β”‚ β”‚ SLA Terms     β”‚ β”‚
β”‚ β”‚ Parts/Labor   β”‚ β”‚ β”‚ β”‚ Scheduling    β”‚ β”‚ β”‚ β”‚ Approvals     β”‚ β”‚
β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β”‚ β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β”‚ β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β”‚
β”‚ OData/RFC/IDoc    β”‚ β”‚ REST API v2       β”‚ β”‚ Generic REST      β”‚
β”‚ Circuit Breaker   β”‚ β”‚ OAuth 2.0         β”‚ β”‚ Custom Auth       β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
         β”‚                        β”‚                        β”‚
         β–Ό                        β–Ό                        β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚   SAP S/4HANA     β”‚ β”‚    ServiceNow     β”‚ β”‚      CLM          β”‚
β”‚                   β”‚ β”‚                   β”‚ β”‚   (Icertis/       β”‚
β”‚ β€’ Plant Maint(PM) β”‚ β”‚ β€’ ITSM            β”‚ β”‚   DocuSign/       β”‚
β”‚ β€’ Asset Hierarchy β”‚ β”‚ β€’ Field Service   β”‚ β”‚   Agiloft)        β”‚
β”‚ β€’ Work Orders     β”‚ β”‚ β€’ Dispatch        β”‚ β”‚                   β”‚
β”‚ β€’ Inventory       β”‚ β”‚ β€’ Mobile Apps     β”‚ β”‚ β€’ Service Contractsβ”‚
β”‚ β€’ Confirmations   β”‚ β”‚ β€’ SLA Management  β”‚ β”‚ β€’ Rate Management β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

🎯 Key Features

API-Led Architecture

  • Experience Layer: Purpose-built for Agentforce & human apps
  • Process Layer: Cross-system orchestration with saga patterns
  • System Layer: Vendor abstraction with unified contracts

Security & Governance

  • OAuth 2.0 client credentials for machine-to-machine
  • JWT validation for user contexts
  • mTLS between API layers
  • Rate limiting with SLA tiers
  • OWASP security policies
  • Idempotency keys for safe retries

Observability & Monitoring

  • Distributed tracing with correlation IDs
  • Structured JSON logging with PII masking
  • Anypoint Monitoring dashboards
  • Business metrics (MTTR, SLA compliance)
  • Error aggregation and alerting

Data Consistency

  • Event-driven architecture with Anypoint MQ
  • Asset cache with TTL-based refresh
  • Optimistic locking with ETags
  • Compensation patterns for failures
  • Replay-safe message processing

πŸ—οΈ Project Structure

energy-field-service-integration/
β”œβ”€β”€ shared-models/                    # Canonical data models
β”‚   └── src/main/resources/
β”‚       β”œβ”€β”€ schemas/                  # JSON Schema definitions
β”‚       β”‚   β”œβ”€β”€ Asset.json
β”‚       β”‚   β”œβ”€β”€ WorkOrder.json
β”‚       β”‚   β”œβ”€β”€ Contract.json
β”‚       β”‚   └── EventEnvelope.json
β”‚       └── dw/types/                 # DataWeave type definitions
β”‚           β”œβ”€β”€ AssetType.dwl
β”‚           β”œβ”€β”€ WorkOrderType.dwl
β”‚           β”œβ”€β”€ ContractType.dwl
β”‚           β”œβ”€β”€ EventType.dwl
β”‚           └── ErrorType.dwl
β”‚
β”œβ”€β”€ experience-energy-ops-api/        # Experience Layer
β”‚   β”œβ”€β”€ src/main/
β”‚   β”‚   β”œβ”€β”€ mule/
β”‚   β”‚   β”‚   β”œβ”€β”€ app.xml              # Main API flow & APIKit
β”‚   β”‚   β”‚   β”œβ”€β”€ global.xml           # Global configs & security
β”‚   β”‚   β”‚   β”œβ”€β”€ work-order-flows.xml # Work order business logic
β”‚   β”‚   β”‚   β”œβ”€β”€ asset-flows.xml      # Asset context & caching
β”‚   β”‚   β”‚   └── dispatch-flows.xml   # Dispatch & estimation
β”‚   β”‚   └── resources/
β”‚   β”‚       β”œβ”€β”€ api/
β”‚   β”‚       β”‚   └── experience-energy-ops-api.yaml
β”‚   β”‚       β”œβ”€β”€ config-dev.yaml
β”‚   β”‚       β”œβ”€β”€ config-staging.yaml
β”‚   β”‚       β”œβ”€β”€ config-prod.yaml
β”‚   β”‚       └── secure-config-${env}.yaml
β”‚   └── src/test/munit/              # MUnit test suites
β”‚
β”œβ”€β”€ process-field-service-orch-api/   # Process Layer
β”‚   β”œβ”€β”€ src/main/mule/
β”‚   β”‚   β”œβ”€β”€ orchestration-flows.xml  # Main orchestration logic
β”‚   β”‚   β”œβ”€β”€ saga-flows.xml           # Saga & compensation patterns
β”‚   β”‚   β”œβ”€β”€ event-flows.xml          # Event processing & MQ
β”‚   β”‚   └── integration-flows.xml    # System API calls
β”‚   └── src/test/munit/
β”‚
β”œβ”€β”€ system-sap-eam-api/              # SAP System API
β”‚   β”œβ”€β”€ src/main/mule/
β”‚   β”‚   β”œβ”€β”€ sap-asset-flows.xml      # Asset master operations
β”‚   β”‚   β”œβ”€β”€ sap-maintenance-flows.xml # Work order operations
β”‚   β”‚   └── sap-integration-flows.xml # OData/RFC/IDoc handling
β”‚
β”œβ”€β”€ system-servicenow-api/           # ServiceNow System API
β”‚   β”œβ”€β”€ src/main/mule/
β”‚   β”‚   β”œβ”€β”€ snow-incident-flows.xml   # Incident/Work Order CRUD
β”‚   β”‚   β”œβ”€β”€ snow-dispatch-flows.xml   # Technician assignment
β”‚   β”‚   └── snow-integration-flows.xml # REST API v2 handling
β”‚
β”œβ”€β”€ system-clm-api/                  # Contract Management System API
β”‚   β”œβ”€β”€ src/main/mule/
β”‚   β”‚   β”œβ”€β”€ clm-contract-flows.xml    # Contract operations
β”‚   β”‚   β”œβ”€β”€ clm-ratecard-flows.xml    # Rate management
β”‚   β”‚   └── clm-integration-flows.xml # Generic REST handling
β”‚
β”œβ”€β”€ deployment/                      # CI/CD & Deployment
β”‚   β”œβ”€β”€ cloudhub2/                   # CloudHub 2.0 configs
β”‚   β”œβ”€β”€ rtf/                         # Runtime Fabric configs
β”‚   β”œβ”€β”€ github-actions/              # CI/CD workflows
β”‚   └── docker/                      # Container definitions
β”‚
└── docs/                           # Additional documentation
    β”œβ”€β”€ api-specifications/         # Complete OAS files
    β”œβ”€β”€ integration-patterns/       # Pattern documentation
    └── troubleshooting/           # Runbooks & guides

πŸš€ Quick Start

Prerequisites

  • Java 17
  • Maven 3.8+
  • Anypoint Studio 7.x
  • Anypoint Platform account
  • Access to SAP, ServiceNow, Salesforce, CLM systems

Local Development Setup

  1. Clone and Build

    git clone <repository-url>
    cd energy-field-service-integration
    mvn clean install
  2. Configure Secure Properties

    # Create secure configuration files
    cp src/main/resources/secure-config-template.yaml src/main/resources/secure-config-dev.yaml
    
    # Update with your credentials
    # Use Anypoint CLI to encrypt sensitive values
    anypoint-cli secure-properties encrypt --value "your-secret" --key "encryption-key"
  3. Start Applications

    # Start each application (in separate terminals)
    cd experience-energy-ops-api && mvn mule:run
    cd process-field-service-orch-api && mvn mule:run
    cd system-sap-eam-api && mvn mule:run
    cd system-servicenow-api && mvn mule:run
    cd system-clm-api && mvn mule:run

Configuration Files

config-dev.yaml (Experience API)

# HTTP Configuration
http:
  host: "0.0.0.0"
  port: "8081"

# TLS Configuration  
tls:
  keystore:
    path: "keystore.jks"
    password: "!{secure::keystore.password}"
    key:
      password: "!{secure::keystore.key.password}"
  truststore:
    path: "truststore.jks"
    password: "!{secure::truststore.password}"

# API Configuration
api:
  base:
    url: "https://localhost:8081/field-service/v1"
    
# Process API Configuration
process:
  api:
    host: "localhost"
    port: "8082"
    client:
      id: "!{secure::process.api.client.id}"
      secret: "!{secure::process.api.client.secret}"
    token:
      url: "https://auth.energy.com/oauth2/token"

# Salesforce Configuration
salesforce:
  username: "!{secure::salesforce.username}"
  password: "!{secure::salesforce.password}"
  security:
    token: "!{secure::salesforce.security.token}"
  consumer:
    key: "!{secure::salesforce.consumer.key}"
    secret: "!{secure::salesforce.consumer.secret}"
  login:
    url: "https://login.salesforce.com/services/oauth2/token"

# OAuth Configuration
oauth:
  issuer: "https://auth.energy.com"

# Rate Limiting
rate:
  limit:
    requests:
      per:
        minute: 100

# Application Metadata
app:
  version: "1.0.0"
env: "dev"

# Security (for testing only)
test:
  username: "testuser"
  password: "testpass"

πŸ”§ Key Flows Implementation

1. Create Work Order Flow (Agentforce β†’ ServiceNow)

sequenceDiagram
    participant AF as Agentforce
    participant EXP as Experience API
    participant PROC as Process API  
    participant SAP as SAP System API
    participant CLM as CLM System API
    participant SNOW as ServiceNow API
    participant SF as Salesforce

    AF->>EXP: POST /work-orders (caseId, assetId, symptoms)
    EXP->>EXP: Validate OAuth/JWT + Rate Limit
    EXP->>EXP: Check Idempotency Key
    EXP->>PROC: GET /assets/{assetId}
    PROC->>SAP: Fetch asset context
    SAP-->>PROC: Asset details + maintenance history
    PROC-->>EXP: Enriched asset context
    
    EXP->>PROC: GET /contracts/applicable
    PROC->>CLM: Find contracts by location/vendor
    CLM-->>PROC: Rate cards + SLA terms
    PROC-->>EXP: Best-fit contract
    
    EXP->>PROC: POST /estimates/calculate
    PROC-->>EXP: Cost breakdown
    
    EXP->>PROC: POST /work-orders
    PROC->>SNOW: Create work order/incident
    PROC->>SF: Create/update Case task
    PROC->>SAP: Create maintenance notification
    PROC-->>EXP: Work order with external IDs
    
    EXP-->>AF: 201 Created + Work Order details
Loading

2. Status Sync Flow (ServiceNow β†’ Agentforce & SAP)

sequenceDiagram
    participant SNOW as ServiceNow
    participant SNOW_API as ServiceNow API
    participant PROC as Process API
    participant SAP_API as SAP System API
    participant SAP as SAP S/4HANA
    participant SF as Salesforce
    participant MQ as Anypoint MQ

    SNOW->>SNOW_API: Work order status update webhook
    SNOW_API->>PROC: POST /work-orders/{id}/status
    PROC->>PROC: Transform to canonical WorkOrder
    
    alt Status = COMPLETED
        PROC->>SAP_API: POST /confirmations
        SAP_API->>SAP: Goods issue + time confirmation
        SAP-->>SAP_API: Success
    end
    
    PROC->>SF: Update Case/Task status
    SF-->>PROC: Success
    
    PROC->>MQ: Publish workorder.status.changed event
    MQ-->>PROC: Event published
    
    PROC-->>SNOW_API: 200 OK
Loading

3. Asset Master Sync (SAP β†’ Experience Cache)

sequenceDiagram
    participant SCHEDULER as Anypoint Scheduler
    participant PROC as Process API
    participant SAP_API as SAP System API
    participant SAP as SAP S/4HANA
    participant CACHE as Object Store
    participant MQ as Anypoint MQ

    SCHEDULER->>PROC: Trigger asset delta sync
    PROC->>SAP_API: GET /assets/delta?since=lastSync
    SAP_API->>SAP: Query changed assets (EQUI/FUNC)
    SAP-->>SAP_API: Delta asset records
    SAP_API-->>PROC: Normalized asset list
    
    loop For each changed asset
        PROC->>PROC: Transform to canonical Asset
        PROC->>CACHE: Update asset cache
        PROC->>MQ: Publish asset.changed event
    end
    
    PROC->>PROC: Update last sync timestamp
Loading

πŸ” Security Implementation

OAuth 2.0 Client Credentials Flow

<!-- OAuth Provider Configuration -->
<oauth:provider-config name="oauth-provider">
    <oauth:client-credentials-grant-type 
        clientId="${oauth.client.id}"
        clientSecret="${oauth.client.secret}"
        tokenUrl="${oauth.token.url}">
        <oauth:token-validation>
            <oauth:jwt-validation 
                issuer="${oauth.issuer}"
                audience="${oauth.audience}" />
        </oauth:token-validation>
    </oauth:client-credentials-grant-type>
</oauth:provider-config>

Rate Limiting Implementation

<!-- Rate Limiting with Object Store -->
<flow name="rate-limiting-flow">
    <set-variable variableName="clientKey" 
                 value="#[vars.clientId ++ ':' ++ attributes.remoteAddress]" />
    <set-variable variableName="rateLimitKey" 
                 value="#['rate-limit:' ++ vars.clientKey ++ ':' ++ 
                        ((now() as Number) / 60000 as Number {format: '0'})]" />
    
    <os:retrieve key="#[vars.rateLimitKey]" 
                objectStore="rate-limit-store" />
    <validation:is-true expression="#[(payload as Number + 1) <= ${rate.limit.requests.per.minute}]"
                      message="Rate limit exceeded" />
    
    <os:store key="#[vars.rateLimitKey]" 
             objectStore="rate-limit-store">
        <os:value>#[payload as Number + 1]</os:value>
    </os:store>
</flow>

πŸ“Š Monitoring & Observability

Structured Logging

<json-logger:logger config-ref="json-logger-config" 
                   message="Work Order Created">
    <json-logger:content><![CDATA[
        {
            "correlationId": "$(correlationId)",
            "workOrderId": "$(vars.workOrderId)",
            "assetId": "$(vars.assetId)",
            "priority": "$(vars.priority)",
            "estimatedCost": "$(vars.costEstimate.total)",
            "responseTime": "$((now() - vars.startTime) as Number)",
            "timestamp": "$(now())"
        }
    ]]></json-logger:content>
</json-logger:logger>

Business Metrics

  • Work orders created per hour/day
  • Mean Time to Resolution (MTTR)
  • SLA compliance percentage
  • Cost accuracy (estimated vs actual)
  • Asset utilization rates
  • Contract utilization by vendor

Key Performance Indicators

  • API response time < 2s (95th percentile)
  • System availability > 99.9%
  • Error rate < 0.1%
  • Cache hit ratio > 80%
  • Message processing latency < 500ms

πŸ§ͺ Testing Strategy

MUnit Test Structure

<!-- Example MUnit Test -->
<munit:test name="create-work-order-test" description="Test work order creation">
    <munit:behavior>
        <munit-tools:mock-when processor="http:request" doc:name="Mock Process API">
            <munit-tools:with-attributes>
                <munit-tools:with-attribute whereValue="process-api-config" attributeName="config-ref"/>
            </munit-tools:with-attributes>
            <munit-tools:then-return>
                <munit-tools:payload value="#[{woId: 'WO0000123456', status: 'NEW'}]"/>
            </munit-tools:then-return>
        </munit-tools:mock-when>
    </munit:behavior>
    
    <munit:execution>
        <flow-ref name="create-work-order-flow"/>
    </munit:execution>
    
    <munit:validation>
        <munit-tools:assert-that expression="#[payload.woId]" 
                                is="#[MunitTools::notNullValue()]"/>
        <munit-tools:assert-equals actual="#[payload.status]" expected="NEW"/>
    </munit:validation>
</munit:test>

Test Categories

  • Unit Tests: Individual flow testing with mocks
  • Integration Tests: End-to-end API testing
  • Contract Tests: OAS specification validation
  • Load Tests: Performance under stress
  • Security Tests: Authentication & authorization
  • Chaos Tests: Resilience testing

🚒 Deployment

CloudHub 2.0 Deployment

# deployment/cloudhub2/experience-api-deployment.yaml
apiVersion: v1alpha1
kind: Application
metadata:
  name: experience-energy-ops-api
  environment: production
spec:
  image: experience-energy-ops-api:1.0.0
  replicas: 3
  resources:
    vcores: 2.0
    memory: 4Gi
  networking:
    ingress:
      enabled: true
      host: api.energy.com
      tls:
        enabled: true
  monitoring:
    enabled: true
    metrics:
      - business.metrics
      - performance.metrics

Runtime Fabric (RTF) Deployment

# Deploy to RTF
anypoint-cli runtime-fabric deploy \
  --application-name experience-energy-ops-api \
  --target production-rtf \
  --artifact-path target/experience-energy-ops-api-1.0.0-mule-application.jar \
  --replicas 3 \
  --cpu-limit 2000m \
  --memory-limit 4Gi

CI/CD Pipeline (GitHub Actions)

# .github/workflows/deploy.yml
name: Deploy Energy APIs
on:
  push:
    branches: [main]

jobs:
  test:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v3
      - uses: actions/setup-java@v3
        with:
          java-version: '17'
      - run: mvn clean test
      
  build-and-deploy:
    needs: test
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v3
      - uses: actions/setup-java@v3
        with:
          java-version: '17'
      - run: mvn clean package -DskipTests
      - run: |
          anypoint-cli login \
            --username ${{ secrets.ANYPOINT_USERNAME }} \
            --password ${{ secrets.ANYPOINT_PASSWORD }}
          anypoint-cli cloudhub2 deploy \
            --application-name experience-energy-ops-api-prod \
            --artifact target/*.jar \
            --replicas 3

πŸ₯ Health Checks & Monitoring

Health Check Endpoints

<!-- Health Check Flow -->
<flow name="health-check-flow">
    <http:listener path="/health" config-ref="httpListenerConfig"/>
    <choice>
        <when expression="#[attributes.queryParams.deep == 'true']">
            <parallel-foreach collection="#[['process-api', 'sap-api', 'snow-api', 'clm-api']]">
                <try>
                    <http:request method="GET" 
                                 path="/health"
                                 config-ref="#[payload ++ '-config']"/>
                    <set-payload value="#[{service: payload, status: 'UP', responseTime: vars.responseTime}]"/>
                    <error-handler>
                        <on-error-continue>
                            <set-payload value="#[{service: payload, status: 'DOWN', error: error.description}]"/>
                        </on-error-continue>
                    </error-handler>
                </try>
            </parallel-foreach>
            <set-payload value="#[{
                status: if (payload..status contains 'DOWN') 'DEGRADED' else 'UP',
                timestamp: now(),
                services: payload,
                version: '${app.version}',
                environment: '${env}'
            }]"/>
        </when>
        <otherwise>
            <set-payload value="#[{
                status: 'UP',
                timestamp: now(),
                version: '${app.version}',
                environment: '${env}'
            }]"/>
        </otherwise>
    </choice>
</flow>

πŸ“ˆ Performance Optimization

Caching Strategy

  • Asset Cache: 4-hour TTL with background refresh
  • Contract Cache: 24-hour TTL with change notifications
  • Rate Limit Cache: 1-minute sliding window
  • Authentication Cache: 15-minute JWT validation cache

Connection Pooling

<http:request-connection-provider name="pooled-connection-provider">
    <http:pooling-profile 
        maxActive="50"
        maxIdle="10"
        exhaustedAction="WHEN_EXHAUSTED_WAIT"
        maxWait="60000"/>
    <http:tcp-client-socket-properties 
        connectionTimeout="30000"
        keepAlive="true"/>
</http:request-connection-provider>

πŸ› Troubleshooting

Common Issues

  1. OAuth Token Expiration

    Error: OAUTH:TOKEN_UNAUTHORIZED
    Solution: Check token expiration and refresh logic
    
  2. Rate Limit Exceeded

    Error: HTTP:TOO_MANY_REQUESTS
    Solution: Implement exponential backoff in client
    
  3. SAP Connection Issues

    Error: SAP:RFC_EXCEPTION
    Solution: Check SAP gateway configuration and user permissions
    
  4. ServiceNow Timeout

    Error: HTTP:TIMEOUT
    Solution: Increase timeout values and implement circuit breaker
    

Debug Endpoints

  • GET /health - Application health status
  • GET /health?deep=true - Deep health check with dependencies
  • GET /metrics - Performance metrics
  • GET /config - Configuration validation (non-sensitive only)

πŸ“š Additional Resources

🀝 Contributing

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/AmazingFeature)
  3. Commit your changes (git commit -m 'Add some AmazingFeature')
  4. Push to the branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request

πŸ“„ License

This project is proprietary software owned by Energy Corp. All rights reserved.


Contact: Field Service API Team - [email protected] Version: 1.0.0 Last Updated: January 2024

About

πŸš€ Production-ready MuleSoft API-led architecture for Oil & Gas field service operations integrating Salesforce Agentforce, ServiceNow, SAP S/4HANA, and Contract Management systems

Topics

Resources

License

Contributing

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published