This repository has been archived by the owner on Jul 6, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 100
Adding Text Analytics module (Cognitive Services) #557
Merged
zhongyi-zhang
merged 13 commits into
Azure:master
from
neilpeterson:rename-module-to-text-analytics
Sep 28, 2018
Merged
Changes from 8 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
54a7e2c
Adding Text Analytics module (cognitve services)
neilpeterson 2e1c0d1
Merge branch 'master' into rename-module-to-text-analytics
neilpeterson 5abbd76
Merge branch 'master' into rename-module-to-text-analytics
neilpeterson a47d844
Merge branch 'master' into rename-module-to-text-analytics
neilpeterson 321a8d6
Merge branch 'master' into rename-module-to-text-analytics
jeremyrickard 7606d13
Merge branch 'master' into rename-module-to-text-analytics
jeremyrickard bf08e76
ran make dep
neilpeterson d5a2b07
Fix merge conflict
neilpeterson 0ee48d1
Removed unused parameter and added credentials test
neilpeterson 1e17a0d
Merge branch 'master' into rename-module-to-text-analytics
neilpeterson b8ff1c9
Merge branch 'master' into rename-module-to-text-analytics
zhongyi-zhang aff4b5a
Merge branch 'master' into rename-module-to-text-analytics
ae36d00
Ran make dep and fixed lint issues
neilpeterson File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
# [Azure Text Analytics](https://azure.microsoft.com/en-us/services/cognitive-services/text-analytics/) | ||
|
||
_Note: This module is EXPERIMENTAL and future releases may break the API._ | ||
|
||
## Services & Plans | ||
|
||
### Service: azure-text-analytics | ||
|
||
| Plan Name | Description | | ||
|-----------|-------------| | ||
| `free` | Free with 5,000 monthly transactions and no overage. | | ||
| `standard-s0` | 25,000 monthly transactions and 3.00 per 1,000 overage. | | ||
| `standard-s1` | 100,000 monthly transactions and 2.50 per 1,000 overage. | | ||
| `standard-s2` | 500,000 monthly transactions and 2.00 per 1,000 overage. | | ||
| `standard-s3` | 2,500,000 monthly transactions and 1.00 per 1,000 overage. | | ||
| `standard-s4` | 10,000,000 monthly transactions and .50 per 1,000 overage. | | ||
|
||
#### Behaviors | ||
|
||
##### Provision | ||
|
||
Provisions a new text analytics API. | ||
|
||
###### Provisioning Parameters | ||
|
||
| Parameter Name | Type | Description | Required | Default Value | | ||
|----------------|------|-------------|----------|---------------| | ||
| `location` | `string` | The Azure region in which to provision applicable resources. | Required _unless_ an administrator has configured the broker itself with a default location. | The broker's default location, if configured. | | ||
| `resourceGroup` | `string` | The (new or existing) resource group with which to associate new resources. | N | If an administrator has configured the broker itself with a default resource group and node is specified, that default will be applied, otherwise, a new resource group will be created with a UUID as its name. | | ||
| `tags` | `map[string]string` | Tags to be applied to new resources, specified as key/value pairs. | N | Tags (even if none are specified) are automatically supplemented with `heritage: open-service-broker-azure`. | | ||
|
||
##### Bind | ||
|
||
Returns the API address and access key. | ||
|
||
###### Binding Parameters | ||
|
||
This binding operation does not support any parameters. | ||
|
||
###### Credentials | ||
|
||
Binding returns the following connection details: | ||
|
||
| Field Name | Type | Description | | ||
|------------|------|-------------| | ||
| `textAnalyticsEndpoint` | `string` | The text analytics API endpoint address. | | ||
| `textAnalyticsKey` | `string` | The text analytics API access key. | | ||
| `textAnalyticsName` | `string` | The name of the text analytics API. | | ||
|
||
##### Unbind | ||
|
||
Does nothing. | ||
|
||
##### Deprovision | ||
|
||
Deletes the text analytics API. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package textanalytics | ||
|
||
// nolint: lll | ||
var armTemplateBytes = []byte(` | ||
{ | ||
"$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#", | ||
"contentVersion": "1.0.0.0", | ||
"parameters": { | ||
"tags": { | ||
"type": "object" | ||
} | ||
}, | ||
"variables": { | ||
"cognitiveservicesid": "[concat(resourceGroup().id,'/providers/','Microsoft.CognitiveServices/accounts/','{{ .name }}')]" | ||
}, | ||
"resources": [{ | ||
"type": "Microsoft.CognitiveServices/accounts", | ||
"sku": { | ||
"name": "{{ .tier }}" | ||
}, | ||
"kind": "TextAnalytics", | ||
"name": "{{ .name }}", | ||
"apiVersion": "2016-02-01-preview", | ||
"location": "{{ .location }}", | ||
"scale": null, | ||
"properties": {}, | ||
"dependsOn": [] | ||
}], | ||
"outputs": { | ||
"cognitivekey": { | ||
"type": "string", | ||
"value": "[listKeys(variables('cognitiveservicesid'),'2016-02-01-preview').key1]" | ||
}, | ||
"endpoint": { | ||
"type": "string", | ||
"value": "[reference(variables('cognitiveservicesid'),'2016-02-01-preview').endpoint]" | ||
}, | ||
"name": { | ||
"type": "string", | ||
"value": "{{ .name }}" | ||
} | ||
} | ||
} | ||
`) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package textanalytics | ||
|
||
import ( | ||
"github.com/Azure/open-service-broker-azure/pkg/service" | ||
) | ||
|
||
func (s *serviceManager) Bind( | ||
service.Instance, | ||
service.BindingParameters, | ||
) (service.BindingDetails, error) { | ||
return nil, nil | ||
} | ||
|
||
func (s *serviceManager) GetCredentials( | ||
instance service.Instance, | ||
_ service.Binding, | ||
) (service.Credentials, error) { | ||
dt := instance.Details.(*instanceDetails) | ||
return &credentials{ | ||
TextAnalyticsKey: dt.TextAnalyticsKey, | ||
Endpoint: dt.Endpoint, | ||
TextAnalyticsName: dt.TextAnalyticsName, | ||
}, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,138 @@ | ||
package textanalytics | ||
|
||
import "github.com/Azure/open-service-broker-azure/pkg/service" | ||
|
||
func (m *module) GetCatalog() (service.Catalog, error) { | ||
return service.NewCatalog([]service.Service{ | ||
service.NewService( | ||
service.ServiceProperties{ | ||
ID: "8f6c848a-4ce1-4a69-9248-63545d3e7e9c", | ||
Name: "azure-text-analytics", | ||
Description: "Azure Text Analytics (Experimental)", | ||
Metadata: service.ServiceMetadata{ | ||
DisplayName: "Azure Text Analytics", | ||
ImageURL: "https://azure.microsoft.com/svghandler/text-analytics/" + | ||
"?width=200", | ||
LongDescription: "Infuse your apps, websites and bots with " + | ||
"intelligent algorithms to see, hear, speak, understand and " + | ||
"interpret your user needs through natural methods of communication." + | ||
" (Experimental)", | ||
DocumentationURL: "https://docs.microsoft.com/en-us/azure/" + | ||
"cognitive-services/text-analytics/", | ||
SupportURL: "https://azure.microsoft.com/en-us/support/", | ||
}, | ||
Bindable: true, | ||
Tags: []string{"Azure", "Cognitive", "Text Analytics", "Analytics"}, | ||
}, | ||
m.serviceManager, | ||
service.NewPlan(service.PlanProperties{ | ||
ID: "d5a0f91f-10da-42fc-b792-656a616d9ec2", | ||
Name: "free", | ||
Description: "Text Analytics Free Tier - max 5,000" + | ||
" transactions per 30 days.", | ||
Free: true, | ||
Extended: map[string]interface{}{ | ||
"textAnalyticsSku": "F0", | ||
}, | ||
Metadata: service.ServicePlanMetadata{ | ||
DisplayName: "Free Tier", | ||
}, | ||
Schemas: service.PlanSchemas{ | ||
ServiceInstances: service.InstanceSchemas{ | ||
ProvisioningParametersSchema: generateProvisioningParamsSchema(), | ||
}, | ||
}, | ||
}), | ||
service.NewPlan(service.PlanProperties{ | ||
ID: "7f49713b-2689-4c66-bac9-85a024c0fb9e", | ||
Name: "standard-s0", | ||
Description: "Text Analytics Standard 0 Tier - max 25,000" + | ||
" transactions per 30 days.", | ||
Free: true, | ||
Extended: map[string]interface{}{ | ||
"textAnalyticsSku": "S0", | ||
}, | ||
Metadata: service.ServicePlanMetadata{ | ||
DisplayName: "Standard 0 Tier", | ||
}, | ||
Schemas: service.PlanSchemas{ | ||
ServiceInstances: service.InstanceSchemas{ | ||
ProvisioningParametersSchema: generateProvisioningParamsSchema(), | ||
}, | ||
}, | ||
}), | ||
service.NewPlan(service.PlanProperties{ | ||
ID: "55575612-482b-4260-b67e-69be36d83a54", | ||
Name: "standard-s1", | ||
Description: "Text Analytics Standard 1 Tier - max 100,000" + | ||
" transactions per 30 days.", | ||
Free: true, | ||
Extended: map[string]interface{}{ | ||
"textAnalyticsSku": "S1", | ||
}, | ||
Metadata: service.ServicePlanMetadata{ | ||
DisplayName: "Standard 1 Tier", | ||
}, | ||
Schemas: service.PlanSchemas{ | ||
ServiceInstances: service.InstanceSchemas{ | ||
ProvisioningParametersSchema: generateProvisioningParamsSchema(), | ||
}, | ||
}, | ||
}), | ||
service.NewPlan(service.PlanProperties{ | ||
ID: "76bc6a2f-1364-4ef2-8037-d7cfff48f3b6", | ||
Name: "standard-s2", | ||
Description: "Text Analytics Standard 2 Tier - max 500,000" + | ||
" transactions per 30 days.", | ||
Free: true, | ||
Extended: map[string]interface{}{ | ||
"textAnalyticsSku": "S2", | ||
}, | ||
Metadata: service.ServicePlanMetadata{ | ||
DisplayName: "Standard 2 Tier", | ||
}, | ||
Schemas: service.PlanSchemas{ | ||
ServiceInstances: service.InstanceSchemas{ | ||
ProvisioningParametersSchema: generateProvisioningParamsSchema(), | ||
}, | ||
}, | ||
}), | ||
service.NewPlan(service.PlanProperties{ | ||
ID: "1d9a9e7c-80ac-4f23-aabe-876125541f59", | ||
Name: "standard-s3", | ||
Description: "Text Analytics Standard 3 Tier - max 2,500,000" + | ||
" transactions per 30 days.", | ||
Free: true, | ||
Extended: map[string]interface{}{ | ||
"textAnalyticsSku": "S3", | ||
}, | ||
Metadata: service.ServicePlanMetadata{ | ||
DisplayName: "Standard 3 Tier", | ||
}, | ||
Schemas: service.PlanSchemas{ | ||
ServiceInstances: service.InstanceSchemas{ | ||
ProvisioningParametersSchema: generateProvisioningParamsSchema(), | ||
}, | ||
}, | ||
}), | ||
service.NewPlan(service.PlanProperties{ | ||
ID: "b9db834d-1350-4c50-adaf-f1e59efa2381", | ||
Name: "standard-s4", | ||
Description: "Text Analytics Standard 4 Tier - max 10,000,000" + | ||
" transactions per 30 days.", | ||
Free: true, | ||
Extended: map[string]interface{}{ | ||
"textAnalyticsSku": "S4", | ||
}, | ||
Metadata: service.ServicePlanMetadata{ | ||
DisplayName: "Standard 4 Tier", | ||
}, | ||
Schemas: service.PlanSchemas{ | ||
ServiceInstances: service.InstanceSchemas{ | ||
ProvisioningParametersSchema: generateProvisioningParamsSchema(), | ||
}, | ||
}, | ||
}), | ||
), | ||
}), nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package textanalytics | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
|
||
"github.com/Azure/open-service-broker-azure/pkg/service" | ||
) | ||
|
||
func (s *serviceManager) GetDeprovisioner( | ||
service.Plan, | ||
) (service.Deprovisioner, error) { | ||
return service.NewDeprovisioner( | ||
service.NewDeprovisioningStep("deleteARMDeployment", s.deleteARMDeployment), | ||
service.NewDeprovisioningStep("deleteContainer", s.deleteContainer), | ||
) | ||
} | ||
|
||
func (s *serviceManager) deleteARMDeployment( | ||
_ context.Context, | ||
instance service.Instance, | ||
) (service.InstanceDetails, error) { | ||
dt := instance.Details.(*instanceDetails) | ||
if err := s.armDeployer.Delete( | ||
dt.ARMDeploymentName, | ||
instance.ProvisioningParameters.GetString("resourceGroup"), | ||
); err != nil { | ||
return nil, fmt.Errorf("error deleting ARM deployment: %s", err) | ||
} | ||
return instance.Details, nil | ||
} | ||
|
||
func (s *serviceManager) deleteContainer( | ||
ctx context.Context, | ||
instance service.Instance, | ||
) (service.InstanceDetails, error) { | ||
ctx, cancel := context.WithCancel(ctx) | ||
defer cancel() | ||
dt := instance.Details.(*instanceDetails) | ||
_, err := s.congnitiveClient.Delete( | ||
ctx, | ||
instance.ProvisioningParameters.GetString("resourceGroup"), | ||
dt.TextAnalyticsName, | ||
) | ||
if err != nil { | ||
return nil, fmt.Errorf("error deleting Cognitive Services account: %s", err) | ||
} | ||
return instance.Details, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package textanalytics | ||
|
||
import ( | ||
"github.com/Azure/open-service-broker-azure/pkg/azure" | ||
"github.com/Azure/open-service-broker-azure/pkg/service" | ||
) | ||
|
||
func generateProvisioningParamsSchema() service.InputParametersSchema { | ||
return service.InputParametersSchema{ | ||
RequiredProperties: []string{"location", "resourceGroup"}, | ||
PropertySchemas: map[string]service.PropertySchema{ | ||
"location": &service.StringPropertySchema{ | ||
Title: "Location", | ||
Description: "The Azure region in which to provision" + | ||
" applicable resources.", | ||
CustomPropertyValidator: azure.LocationValidator, | ||
}, | ||
"resourceGroup": &service.StringPropertySchema{ | ||
Title: "Resource group", | ||
Description: "The (new or existing) resource group with which" + | ||
" to associate new resources.", | ||
}, | ||
"name": &service.StringPropertySchema{ | ||
Title: "Name", | ||
Description: "Text Analytics API name.", | ||
}, | ||
}, | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why make parameter
name
user-specified? In other modules, the name of the server, database, and so on, is generated randomly and is not configurable for users. I'm not familiar with textanalytics, please tell me if there is any special concern to do this. If not, could you makename
randomly generated just like other modules?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for catching this @norshtein . The parameter was actually unused and has been removed.