Skip to content

Commit

Permalink
Merge pull request Azure#198 from jeremymeng/tweak-build-for-processor
Browse files Browse the repository at this point in the history
Apply build configuration from template for EPH
  • Loading branch information
jeremymeng authored Feb 15, 2019
2 parents 9f74580 + 120792c commit 331dcea
Show file tree
Hide file tree
Showing 26 changed files with 2,453 additions and 272 deletions.
28 changes: 0 additions & 28 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,34 +4,6 @@
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"type": "node",
"request": "launch",
"name": "EPH Tests",
"program": "${workspaceFolder}/processor/node_modules/mocha/bin/_mocha",
"args": [
"-u",
"tdd",
"-r",
"ts-node/register",
"-t",
"999999",
"--colors",
"${workspaceFolder}/processor/tests/eph.spec.ts"
],
"internalConsoleOptions": "openOnSessionStart",
"envFile": "${workspaceFolder}/processor/.env" // You can take a look at the sample.env file for supported environment variables.
},
{
"type": "node",
"request": "launch",
"name": "EPH Example",
"program": "${workspaceFolder}/processor/examples/singleEph.ts",
"outFiles": [
"${workspaceFolder}/processor/dist/**/*.js"
],
"envFile": "${workspaceFolder}/processor/.env" // You can take a look at the sample.env file for supported environment variables.
},
{
"type": "node",
"request": "launch",
Expand Down
36 changes: 36 additions & 0 deletions processor/.vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"type": "node",
"request": "launch",
"name": "EPH Tests",
"program": "${workspaceFolder}/node_modules/mocha/bin/_mocha",
"args": [
"-u",
"tdd",
"--timeout",
"999999",
"--colors",
"${workspaceFolder}/test-dist/index.js"
],
"internalConsoleOptions": "openOnSessionStart",
"preLaunchTask": "npm: build-test",
"envFile": "${workspaceFolder}/.env" // You can take a look at the sample.env file for supported environment variables.
},
{
"type": "node",
"request": "launch",
"name": "EPH Example",
"program": "${workspaceFolder}/examples/singleEph.ts",
"outFiles": [
"${workspaceFolder}/dist-esm/**/*.js"
],
"preLaunchTask": "npm: build-samples",
"envFile": "${workspaceFolder}/.env" // You can take a look at the sample.env file for supported environment variables.
}
]
}
48 changes: 48 additions & 0 deletions processor/examples/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
## Getting started with samples ##

## Building the library
- Clone the repo and cd to the repo directory
```bash
git clone https://github.com/Azure/azure-event-hubs-node.git
cd processor
```
- Install typescript, ts-node globally (required for running the samples)
```bash
npm i -g typescript
npm i -g ts-node
```
- NPM install from the root of the package
```bash
npm i
```
- Build the project
```bash
npm run build
```

## Before executing a sample
- Go to the [Azure Portal](https://portal.azure.com).
- Here are the docs which would help you create a event hubs and eventhub/iothub resources in the portal :
- [Azure Event Hubs - NodeJS DOCS](https://docs.microsoft.com/en-us/azure/event-hubs/event-hubs-node-get-started-send).
- [Azure IoT Hubs - NodeJS DOCS](https://docs.microsoft.com/en-us/azure/iot-hub/iot-hub-node-node-module-twin-getstarted).
- In the portal, go to **Dashboard > Event Hubs > _your-eventhubs-namespace_**.
- Note down the "Primary Connection String" of **RootManageSharedAccessKey** at **Shared access policies** in the **Settings** section.
- Note down the name of the event hub that you created
> _Note : **RootManageSharedAccessKey** is automatically created for the namespace and has permissions for the entire namespace. If you want to use restricted access, refer [Shared Access Signatures](https://docs.microsoft.com/en-us/azure/service-bus-messaging/service-bus-sas), create the Access Keys exclusive to the specific created Queue/Topic._
- You would also need an Azure Storage Account for all the `*Eph.ts` examples. The docs are at
[Create a storage account](https://docs.microsoft.com/en-us/azure/storage/common/storage-quickstart-create-account?tabs=azure-portal). After the storage account is created, find the connection string at **Access keys** tab in the **Settings** section.
Before running a sample, update it with the connection string and the hub name you have noted down above.
- to load environment variables from an `.env` file, please refer to [NPM dotenv package](https://www.npmjs.com/package/dotenv) for more details. See the [sample.env](../../sample.env) for an example.

## Executing a sample
- The samples are to be run using ts-node, after changing your current working directory to the `examples` folder.

```bash
cd examples
ts-node <sample>.ts
```
- For debugging:
[VS Code - Debugging](https://code.visualstudio.com/docs/editor/debugging#_launch-configurations) - Update the `EPH Example` configuration in `launch.json` by changing the `program` attrbute to point to the sample you want to debug.
```bash
"program": "${workspaceFolder}/processor/examples/<sample>.ts"
```
2 changes: 1 addition & 1 deletion processor/examples/iothubEph.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import {
EventProcessorHost, OnReceivedError, OnReceivedMessage, EventData, PartitionContext, delay
} from "../lib";
import * as dotenv from "dotenv";
import dotenv from "dotenv";
dotenv.config();

const storageCS = process.env.STORAGE_CONNECTION_STRING;
Expand Down
2 changes: 1 addition & 1 deletion processor/examples/multiEph.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import {
EventProcessorHost, OnReceivedError, OnReceivedMessage, EventData, PartitionContext, delay
} from "../lib";
import * as dotenv from "dotenv";
import dotenv from "dotenv";
dotenv.config();

// set the values from environment variables.
Expand Down
2 changes: 1 addition & 1 deletion processor/examples/sendBatch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Licensed under the MIT License.

import { EventHubClient, EventData, delay } from "@azure/event-hubs";
import * as dotenv from "dotenv";
import dotenv from "dotenv";
dotenv.config();

const connectionString = "EVENTHUB_CONNECTION_STRING";
Expand Down
2 changes: 1 addition & 1 deletion processor/examples/singleEph.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import {
EventProcessorHost, OnReceivedError, OnReceivedMessage, EventData, PartitionContext, delay
} from "../lib";
import * as dotenv from "dotenv";
import dotenv from "dotenv";
dotenv.config();

const path = process.env.EVENTHUB_NAME;
Expand Down
13 changes: 13 additions & 0 deletions processor/examples/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"extends": "../tsconfig.json",
"compilerOptions": {
"module": "commonjs"
},
"include": [
"**/*.ts"
],
"exclude": [
"../node_modules",
"../typings/**",
]
}
60 changes: 30 additions & 30 deletions processor/lib/azureBlob.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,72 +34,72 @@ export class AzureBlob {
}
}

async ensureContainerExists(): Promise<CreateContainerResult> {
return await this._blobService.ensureContainerExists(this._containerName);
ensureContainerExists(): Promise<CreateContainerResult> {
return this._blobService.ensureContainerExists(this._containerName);
}

async doesContainerExist(): Promise<boolean> {
return await this._blobService.doesContainerExist(this._containerName);
doesContainerExist(): Promise<boolean> {
return this._blobService.doesContainerExist(this._containerName);
}

async doesBlobExist(): Promise<boolean> {
return await this._blobService.doesBlobExist(this._containerName, this._blobPath);
doesBlobExist(): Promise<boolean> {
return this._blobService.doesBlobExist(this._containerName, this._blobPath);
}

async ensureBlobExists(text: string): Promise<void> {
return await this._blobService.ensureBlobExists(this._containerName, this._blobPath, text);
ensureBlobExists(text: string): Promise<void> {
return this._blobService.ensureBlobExists(this._containerName, this._blobPath, text);
}

async renewLease(leaseId: string,
renewLease(leaseId: string,
options: StorageBlobService.LeaseRequestOptions): Promise<StorageBlobService.LeaseResult> {
return await this._blobService.renewLease(this._containerName, this._blobPath, leaseId, options);
return this._blobService.renewLease(this._containerName, this._blobPath, leaseId, options);
}

async releaseLease(leaseId: string,
releaseLease(leaseId: string,
options?: StorageBlobService.LeaseRequestOptions): Promise<StorageBlobService.LeaseResult> {
return await this._blobService.releaseLease(this._containerName, this._blobPath, leaseId, options);
return this._blobService.releaseLease(this._containerName, this._blobPath, leaseId, options);
}

async updateContent(text: string,
updateContent(text: string,
options?: StorageBlobService.CreateBlobRequestOptions): Promise<StorageBlobService.BlobResult> {
return await this._blobService.updateContent(this._containerName, this._blobPath, text, options);
return this._blobService.updateContent(this._containerName, this._blobPath, text, options);
}

async getContent(options?: StorageBlobService.GetBlobRequestOptions): Promise<string> {
return await this._blobService.getContent(this._containerName, this._blobPath, options);
getContent(options?: StorageBlobService.GetBlobRequestOptions): Promise<string> {
return this._blobService.getContent(this._containerName, this._blobPath, options);
}

async changeLease(currentLeaseId: string,
changeLease(currentLeaseId: string,
proposedLeaseId: string): Promise<StorageBlobService.LeaseResult> {
return await this._blobService.changeLease(this._containerName,
return this._blobService.changeLease(this._containerName,
this._blobPath, currentLeaseId, proposedLeaseId);
}

async getBlobProperties(): Promise<StorageBlobService.BlobResult> {
return await this._blobService.getBlobProperties(this._containerName, this._blobPath);
getBlobProperties(): Promise<StorageBlobService.BlobResult> {
return this._blobService.getBlobProperties(this._containerName, this._blobPath);
}

async getBlobMetadata(): Promise<StorageBlobService.BlobResult> {
return await this._blobService.getBlobMetadata(this._containerName, this._blobPath);
getBlobMetadata(): Promise<StorageBlobService.BlobResult> {
return this._blobService.getBlobMetadata(this._containerName, this._blobPath);
}

async setBlobMetadata(metadata: Dictionary<string>,
setBlobMetadata(metadata: Dictionary<string>,
options?: StorageBlobService.BlobRequestOptions): Promise<StorageBlobService.BlobResult> {
return await this._blobService.setBlobMetadata(this._containerName, this._blobPath,
return this._blobService.setBlobMetadata(this._containerName, this._blobPath,
metadata, options);
}

async listBlobsSegmented(options?: StorageBlobService.ListBlobsSegmentedRequestOptions):
listBlobsSegmented(options?: StorageBlobService.ListBlobsSegmentedRequestOptions):
Promise<StorageBlobService.ListBlobsResult> {
return await this._blobService.listBlobsSegmented(this._containerName, options);
return this._blobService.listBlobsSegmented(this._containerName, options);
}

async acquireLease(options: StorageBlobService.AcquireLeaseRequestOptions):
acquireLease(options: StorageBlobService.AcquireLeaseRequestOptions):
Promise<StorageBlobService.LeaseResult> {
return await this._blobService.acquireLease(this._containerName, this._blobPath, options);
return this._blobService.acquireLease(this._containerName, this._blobPath, options);
}

async deleteBlobIfExists(): Promise<void> {
return await this._blobService.deleteBlobIfExists(this._containerName, this._blobPath);
deleteBlobIfExists(): Promise<void> {
return this._blobService.deleteBlobIfExists(this._containerName, this._blobPath);
}
}
12 changes: 6 additions & 6 deletions processor/lib/azureStorageCheckpointLeaseManager.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

import * as uuid from "uuid/v4";
import uuid from "uuid/v4";
import { CheckpointInfo } from "./checkpointInfo";
import { CheckpointManager } from "./checkpointManager";
import { LeaseManager } from "./leaseManager";
Expand All @@ -19,7 +19,7 @@ import {
leaseIdMismatchWithLeaseOperation, leaseIdMismatchWithBlobOperation
} from "./util/constants";
import * as log from "./log";
const path = require("path-browserify");
import path from "path";

/**
* @ignore
Expand Down Expand Up @@ -76,8 +76,8 @@ export class AzureStorageCheckpointLeaseManager implements CheckpointManager, Le
}
}

async leaseStoreExists(): Promise<boolean> {
return await this._context.blobService!.doesContainerExist(this._context.storageContainerName!);
leaseStoreExists(): Promise<boolean> {
return this._context.blobService!.doesContainerExist(this._context.storageContainerName!);
}

async createLeaseStoreIfNotExists(): Promise<void> {
Expand Down Expand Up @@ -351,9 +351,9 @@ export class AzureStorageCheckpointLeaseManager implements CheckpointManager, Le
return result;
}

async checkpointStoreExists(): Promise<boolean> {
checkpointStoreExists(): Promise<boolean> {
log.checkpointLeaseMgr(this._context.withHost("Checking whether the checkpoint store exists."));
return await this.leaseStoreExists();
return this.leaseStoreExists();
}

async deleteCheckpointStore(): Promise<void> {
Expand Down
2 changes: 1 addition & 1 deletion processor/lib/blobService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { createBlobService, BlobService as StorageBlobService, ServiceResponse }
import * as log from "./log";
import { validateType, getStorageError } from "./util/utils";
import { defaultMaximumExecutionTimeInMs } from "./util/constants";
const path = require("path-browserify");
import path from "path";
/**
* @ignore
*/
Expand Down
12 changes: 6 additions & 6 deletions processor/lib/eventProcessorHost.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

import * as uuid from "uuid/v4";
import uuid from "uuid/v4";
import {
TokenProvider, EventHubRuntimeInformation, EventHubPartitionRuntimeInformation,
AadTokenProvider, EventHubClient
Expand Down Expand Up @@ -67,8 +67,8 @@ export class EventProcessorHost {
* Provides the eventhub runtime information.
* @returns {Promise<EventHubRuntimeInformation>}
*/
async getHubRuntimeInformation(): Promise<EventHubRuntimeInformation> {
return await this._context.getHubRuntimeInformation();
getHubRuntimeInformation(): Promise<EventHubRuntimeInformation> {
return this._context.getHubRuntimeInformation();
}

/**
Expand All @@ -77,15 +77,15 @@ export class EventProcessorHost {
*
* @returns {EventHubPartitionRuntimeInformation} EventHubPartitionRuntimeInformation
*/
async getPartitionInformation(partitionId: string | number): Promise<EventHubPartitionRuntimeInformation> {
return await this._context.getPartitionInformation(partitionId);
getPartitionInformation(partitionId: string | number): Promise<EventHubPartitionRuntimeInformation> {
return this._context.getPartitionInformation(partitionId);
}

/**
* Provides an array of partitionIds.
* @returns {Promise<string[]>}
*/
async getPartitionIds(): Promise<string[]> {
getPartitionIds(): Promise<string[]> {
return this._context.getPartitionIds();
}

Expand Down
4 changes: 2 additions & 2 deletions processor/lib/hostContext.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

import * as uuid from "uuid/v4";
import uuid from "uuid/v4";
import {
EventHubClient, EventPosition, TokenProvider, DefaultDataTransformer, Dictionary,
EventHubRuntimeInformation, EventHubPartitionRuntimeInformation, EventHubConnectionConfig
} from "@azure/event-hubs";
import * as AsyncLock from "async-lock";
import AsyncLock from "async-lock";
import { LeaseManager } from "./leaseManager";
import { PumpManager } from "./pumpManager";
import { PartitionManager } from "./partitionManager";
Expand Down
2 changes: 1 addition & 1 deletion processor/lib/log.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

import * as debugModule from "debug";
import debugModule from "debug";
/**
* @ignore
* log statements for error
Expand Down
2 changes: 1 addition & 1 deletion processor/lib/partitionScanner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ export class PartitionScanner {
} else if (lease) {
this._leaseOwnedByOthers.set(lease.partitionId, lease);
}
return;
return Promise.resolve();
}).catch((err) => {
const msg = `An error occurred while getting/acquiring lease for partitionId ` +
`'${thisLease.partitionId}': ${err ? err.stack : JSON.stringify(err)}`;
Expand Down
Loading

0 comments on commit 331dcea

Please sign in to comment.