JSPM

@sourceloop/ctrl-plane-orchestrator-service

1.2.0
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 9
  • Score
    100M100P100Q55991F
  • License MIT

ARC SaaS Orchestrator service.

Package Exports

  • @sourceloop/ctrl-plane-orchestrator-service
  • @sourceloop/ctrl-plane-orchestrator-service/dist/index.js

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (@sourceloop/ctrl-plane-orchestrator-service) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

ARC By SourceFuse logo

@sourceloop/ctrl-plane-orchestrator-service

npm version GitHub contributors sourceloop orchestrator-service downloads License Pb Loopback

Overview

The @sourceloop/ctrl-plane-orchestrator-service is designed to provide the standard interfaces and endpoint to handle the events sent to/from a SaaS Control Plane. This acts as a orchestrator for the event targets/processors.

Consider the following example architecture that uses Amazon EventBridge at the center to pass on the events, and this Orchestrator service is used as its initial target, so that the events can then be sent to the expected candidates to process the event.

Example Architecture with Orchestrator Service in Use

Above example is of a tenant provisioning event flow, as shown it originates from a control plane service called tenant management service and then when it's received to the Amazon EventBridge, it passes it to the orchestrator service which can run any bussiness logic before it's sent for processing (the example illustrates starting the codebuild or jenkins job conditionally based on the event). Further code examples in this README will take this same reference.

Installation

npm i @sourceloop/ctrl-plane-orchestrator-service

Getting Started

You can start using @sourceloop/ctrl-plane-orchestrator-service in just 4 steps:

  1. Bind Component
  2. Implement Consumers

Bind Component

Bind the OrchestratorServiceComponent to your application constructor as shown below, this will load the built-in artifacts provided by the service in your application to use.

import {OrchestratorServiceComponent} from '@sourceloop/ctrl-plane-orchestrator-service';
// ...
export class MyApplication extends BootMixin(
  ServiceMixin(RepositoryMixin(RestApplication)),
) {
  constructor(options: ApplicationConfig = {}) {
    // ...
    this.component(OrchestratorServiceComponent);
  }
}

This microservice uses message-bus-connector component for consuming the events triggered through the tenant-managenet microservice. It supports multiple message buses.

Usage

Bind the EventStreamConnectorComponent to your application constructor as shown below. This will load the built-in artifacts provided by the Message Bus Connector, enabling event publishing and consumption across different backends like EventBridge, SQS, or BullMQ.

this.component(EventStreamConnectorComponent);

Implement Consumers

Each event type can have one or more Consumers, responsible for reacting to specific messages from the message bus. Use the @consumer decorator to register them automatically. Follow the example as below:

import {consumer, IConsumer, QueueType} from 'loopback4-message-bus-connector';
import {DefaultEventTypes} from '@arc-saas/orchestrator-service';
import {AnyObject} from '@loopback/repository';

@consumer
export class TenantDeploymentConsumer implements IConsumer<AnyObject, string> {
  event = DefaultEventTypes.TENANT_DEPLOYMENT;
  queue = QueueType.EventBridge;

  async handle(detail: AnyObject): Promise<void> {
    console.log('Tenant deployment event received:', detail);
    // Add your business logic here
  }
}

Example Implementations

For more detailed implementation examples, environment setup, and message bus usage (EventBridge, BullMQ, SQS), please refer to sandbox application.

Deployment

The @sourceloop/ctrl-plane-orchestrator-service can be deployed in various ways, including as a serverless application. Here's how you can set it up for serverless deployment, specifically for AWS Lambda.

Serverless Deployment

To deploy this service as a serverless application on AWS Lambda, follow these steps:

  1. Add a lambda.ts file in your src directory. This file will serve as the Lambda entry point:
import {APIGatewayEvent, APIGatewayProxyEvent, Context} from 'aws-lambda';
const serverlessExpress = require('@vendia/serverless-express');

export * from './application';
let serverlessApp: (arg0: APIGatewayProxyEvent, arg1: Context) => any;

export async function setup(event: APIGatewayEvent, context: Context) {
  const {OrchestratorService} = require('./application');
  const config = {
    rest: {
      openApiSpec: {
        setServersFromRequest: true,
      },
    },
  };
  const app = new OrchestratorService(config);
  await app.boot();
  const requestHandler = app.restServer.requestHandler;
  serverlessApp = serverlessExpress({app: requestHandler});
  return serverlessApp(event, context);
}

export const handler = async (event: APIGatewayEvent, context: Context) => {
  if (serverlessApp) {
    return serverlessApp(event, context);
  }

  return setup(event, context);
};
  1. Create a Dockerfile in your project root:
FROM public.ecr.aws/lambda/nodejs:20-x86_64 AS BUILD_IMAGE

RUN mkdir -p ${LAMBDA_TASK_ROOT}

WORKDIR ${LAMBDA_TASK_ROOT}

COPY package*.json ./

RUN npm install

COPY . .

RUN npm run build

CMD [ "./dist/lambda.handler" ]
  1. Build your Docker image:
docker build -t orchestrator-service .
  1. Push the Docker image to your container registry (e.g., Amazon ECR).

  2. Create a Lambda function using the pushed container image.

  3. Configure an API Gateway to trigger your Lambda function.

This setup allows you to run your Orchestrator Service as a serverless application, leveraging AWS Lambda's scalability and cost-efficiency. Remember to adjust your Lambda function's configuration (memory, timeout, etc.) based on your specific needs.

API Documentation

API Details

Visit the OpenAPI spec docs for more details on the APIs provided in this service.

License

ARC SaaS is MIT licensed.