CDK Stepfunction Fargate step that takes all json key - aws-cdk

I wanted to create ECS task that takes all json as its environment input. But my cdk code won't deploy because of following error message, the error message is so vague and it is difficult for me to figure out why my code is wrong.
Failed to call Step Functions for request: 'com.amazonaws.services.stepfunctions.model.CreateStateMachineRequest'. (Service: null; Status Code: 500; Error Code: null; Request ID: null)
new StateMachine (/local/home/miae/Explanation/src/ForecastingDeepLearningExplanationInfrastructure/node_modules/#aws-cdk/aws-stepfunctions/lib/state-machine.ts:101:26)
My cdk code
...
const ecsFargateTask = new sfn.Task(this, 'myEcs', {
inputPath: "$",
resultPath: "$.ecs",
task: new class implements sfn.IStepFunctionsTask {
bind(): sfn.StepFunctionsTaskConfig {
return {
resourceArn: "arn:aws:states:::ecs:runTask.sync",
parameters: {
"LaunchType": "FARGATE",
"Cluster": props.cluster.clusterArn,
"TaskDefinition": taskDefinition.taskDefinitionArn,
"Overrides": {
"ContainerOverrides": [{
"Name": "myContainer",
"Environment.$": "$.envs"
}]
}
}
};
}
}
});
}
const chain = sfn.Chain.start(ecsFargateTask);
new sfn.StateMachine(this, `StateMachineCopy${props.stage}`, {
definition: chain,
timeout: cdk.Duration.seconds(3000)
});
This is the Step function I want, and I could manually create this without problem.
{
"StartAt": "ExplanationEcs",
"States": {
"ExplanationEcs": {
"End": true,
"InputPath": "$",
"Parameters": {
"LaunchType": "FARGATE",
"Cluster": "arn:aws:ecs:us-west-2:123456789:cluster/myCluster482E02CC-1VWQ5XRG4II88",
"TaskDefinition": "arn:aws:ecs:us-west-2:123456789:task-definition/myTaskDefinitionE3E6548C:3",
"Overrides": {
"ContainerOverrides": [
{
"Name": "myContainer",
"Environment.$": "$.envs"
}
]
}
},
"Type": "Task",
"Resource": "arn:aws:states:::ecs:runTask.sync",
"ResultPath": "$.ecs"
}
},
"TimeoutSeconds": 3000
}

Related

How to read an aggregated entity from Odata Service SAP ui5

In OData Model V2, I'm struggling by reading the odata of my mocked server:
I want to get access to the child entity which is associated with a Parent entity.
From Open_Station I can navigate to_Order_Header:
[{
"results": [
{
"__metadata": {
"id": "http://WebService/Open_Station(Station='CHE1',Task='5246')",
"uri": "http://WebService/Open_Station(Station='CHE1',Task='5246')",
"type": "cds_zui_check_dialog.Open_StationType"
},
"Station": "CHE1",
"Task": "5246",
"to_Order_Header": {
"__deferred": {
"uri": "http://WebService/Open_Station(Station='CHE1',Task='5246')/to_Order_Header"
}
}
}
]
}
]
And from to_Order_Header, I can navigate to Order_Item or Stock:
[{
"__metadata" : {
"id" : "http://WebService/Order_Header(OrderNumber='00000000100000000853',Station='CHE1',OrderIndicator='')",
"uri" : "http://WebService/Order_Header(OrderNumber='00000000100000000853',Station='CHE1',OrderIndicator='')",
"type" : "cds_zui_check_dialog.Order_HeaderType"
},
"OrderNumber" : "00000000100000000853",
"Station" : "CHE1",
"OrderIndicator" : "",
"to_Order_Items" : {
"__deferred" : {
"uri" : "http://WebService/Order_Header(OrderNumber='00000000100000000853',Station='CHE1',OrderIndicator='')/to_Order_Items"
}
},
"to_Stock" : {
"__deferred" : {
"uri" : "http://WebService/Order_Header(OrderNumber='00000000100000000853',Station='CHE1',OrderIndicator='')/to_Stock"
}
}
]
In my controller, I have a metho ReadOdata read data like this:
ReadOdata: function()
{
var oModel = new sap.ui.model.odata.v2.ODataModel("http://WebService");
return new Promise(function(resolve, reject)
{
oModel.read("Open_Station(Station='CHE1',Task='5246')/to_Order_Header", {
success : function (data) {
resolve(data);
},
error: function (oError) {
reject(oError);
}
});
});
},
I always get a failure like this:
Request failed with status code 404: GET Open_Station(Station='CHE1',Task='5246')/to_Order_Header
- [{"code":404,"message":"Resource not found","persistent":false,"targets":["/Open_Station(Station='CHE1',Task='5246')/to_Order_Header"],"type":"Error"}]
sap.ui.model.odata.ODataMessageParser
I think the way I want to read the associated entity is wrong. Please help me.
I found a solution. It was a failure in the annotation of the Path:
Instead of writing:
oModel.read("**to_Open_Station**(Station='CHE1',Task='5246')/to_Order_Header", {
I was writing:
oModel.read("*Open_Station*(Station='CHE1',Task='5246')/to_Order_Header", {
In the MetaData, the NavigationProperty was called to_Open_Station.

Extjs 6.7 TreeList load data infinite from remote store

I try to fill a treelist with remote data via a ajax proxy but the treelist shows only the first level and try to reload the sub levels even though the json response contain a complete tree structure. Fiddle link: https://fiddle.sencha.com/#view/editor&fiddle/33u9
When i try to expand the node 'SUB a' (or set the expanded property to true) the store trys to reload the node.
Why is the tree structure from the json response not honored?
Thanks in Advance.
The backend response looks like:
{
"data": {
"root": [
{
"leaf": true,
"text": "Server"
},
{
"leaf": true,
"text": "Storage"
},
{
"text": "SUB a"
"children": [
{
"leaf": true,
"text": "Modul A - 1"
},
{
"leaf": true,
"text": "Modul A - 2"
}
],
},
{
"leaf": true,
"text": "Modul B"
}
]
},
"success": true
}
The used reader config is
reader: {
type: 'json',
rootProperty: 'data.root',
successProperty: 'data.success',
},
After playing around i use the following workaround:
getNavigation: function() {
var me = this,
tree = me.getView().down('navigationtree'),
store = tree.getStore(),
node = store.getRoot();
Ext.Ajax.request({
url: '/getnav',
method: 'POST',
success: function(response) {
var obj = Ext.decode(response.responseText),
childs = obj.data.root;
tree.suspendEvents();
node.removeAll();
childs.forEach(function(item) {
node.appendChild(item);
});
tree.resumeEvents();
},
failure: function(response) {
//debugger;
console.log('server-side failure with status code ' + response.status);
}
}).then(function() {
//debugger;
}
);
}
The funny things is that only the first level of the tree has to be added all following sub-levels are added automaticaly.

Post method with multiple parameter

I am unable to insert multiple rows in database using Post method in MVC web API. I have written code for it but when i am testing by inserting multiple rows through postman it is giving error. At line first the variable "delegatetable" shows null due to which error is coming. i am not doing database connection through entity framework, i have created a DelegateTable class.
public HttpResponseMessage Post(List<DelegateTable> delegatetable)
{
try
{
using (var delegateContext = new ShowContext())
{
foreach (DelegateTable item in delegatetable)
{
DelegateTable delegates = new DelegateTable();
delegates.Salutation__c = item.Salutation__c;
delegates.First_Name__c = item.First_Name__c;
delegates.Last_Name__c = item.Last_Name__c;
delegates.Account_Name__c = item.Account_Name__c;
delegates.Contact_Email__c = item.Contact_Email__c;
delegates.Category__c = item.Category__c;
delegates.Conference_Type__c = item.Conference_Type__c;
delegates.Conference_Selection__c = item.Conference_Selection__c;
delegates.Payment_Statuss__c = item.Payment_Statuss__c;
delegates.Barcode__c = item.Barcode__c;
delegateContext.SaveChanges();
}
var message = Request.CreateResponse(HttpStatusCode.Created, delegatetable);
message.Headers.Location = new Uri(Request.RequestUri.ToString());
return message;
}
}
catch (Exception ex)
{
return Request.CreateErrorResponse(HttpStatusCode.BadRequest, ex);
}
}
Json data that i am passing is below
[
{
"attributes": {
"type": "Registration__c",
"url": "/services/data/v43.0/sobjects/Registration__c/a3h8E0000009VuVQAU"
},
"Salutation__c": "Dr.",
"First_Name__c": "Test",
"Last_Name__c": "Test",
"Account_Name__c": "Test",
"Contact_Email__c": "test123#gmail.com",
"Category__c": "Test",
"Conference_Type__c": null,
"Conference_Selection__c": null,
"Payment_Statuss__c": null,
"Barcode__c": "Test"
},
{
"attributes": {
"type": "Registration__c",
"url": "/services/data/v43.0/sobjects/Registration__c/a3hD0000001kEfOIAU"
},
"Salutation__c": "Mr.",
"First_Name__c": "Demo",
"Last_Name__c": "Demo",
"Account_Name__c": "Demo",
"Contact_Email__c": "Demo#gmail.com",
"Category__c": "Demo",
"Conference_Type__c": null,
"Conference_Selection__c": null,
"Payment_Statuss__c": null,
"Barcode__c": null
}
]
You may try to reformat your payload as a JSON array, as the problem might be that the payload cannot be converted to a List.
Try this:
{
"delegates" :
[
{
"attributes": ..., ...
},
{ "attributes": ..., ...
},
...
]
}

graphql-ruby: Int isn't a defined input type (on $first)

I’ve got a question I can’t seemingly resolve on my own.
Together with basic Query, Mutation and so on types I’ve made the following type definition:
module Types
UserType = GraphQL::ObjectType.define do
name 'User'
description 'A user'
implements GraphQL::Relay::Node.interface
global_id_field :id
field :email, !types.String, 'Email address'
connection :docs, DocType.connection_type, 'Available docs'
end
end
And I then try to query it with:
query FileListQuery(
$after: String
$first: Int
) {
viewer {
currentUser {
docs(first: $first, after: $after) {
edges {
node {
id
name
__typename
}
cursor
}
pageInfo {
endCursor
hasNextPage
hasPreviousPage
startCursor
}
}
id
}
id
}
}
And I pass the following as query variables:
{
"first": 1,
"after": null
}
The problem is it bails out with the following:
{
"errors": [
{
"message": "Int isn't a defined input type (on $first)",
"locations": [
{
"line": 3,
"column": 3
}
],
"fields": [
"query FileListQuery"
]
}
]
}
I honestly have no clue why it complains about the Int type…
If I get rid of the problematic $first query variable in the request, it works fine.
This:
query FileListQuery(
$after: String
) {
viewer {
currentUser {
docs(first: 10, after: $after) {
edges {
node {
id
name
__typename
}
cursor
}
pageInfo {
endCursor
hasNextPage
hasPreviousPage
startCursor
}
}
id
}
id
}
}
Produces this:
{
"data": {
"viewer": {
"currentUser": {
"docs": {
"edges": [
{
"node": {
"id": "1",
"name": "First Doc",
"__typename": "Doc"
},
"cursor": "MQ=="
}
],
"pageInfo": {
"endCursor": "MQ==",
"hasNextPage": false,
"hasPreviousPage": false,
"startCursor": "MQ=="
}
},
"id": "1"
},
"id": "VIEWER"
}
}
}
Any hints, ideas on how to fix this? I use the graphql gem v1.6.3.
Currently, there seems to be a bug in graphql-ruby that prevents types not explicitly used in a schema from being propagated. Check out this issue on GitHub: https://github.com/rmosolgo/graphql-ruby/issues/788#issuecomment-308996229
To fix the error one has to include an Int field somewhere in the schema. Turns out I haven't had one. Yikes.
This fixed it for me:
# Make sure Int is included in the schema:
field :testInt, types.Int

Access Stage results in Workflow/ Pipeline plugin

I have a pipeline with different stages. I want the current job to check how many stages have passed in the previous build and log it in the console?
Consider this is my current pipeline
node(){
stage "1"
do something
stage "2"
do something else
}
I want a groovy script to give my something like this
println currentBuild.previousBuild.getStage("1").result
The purpose of my code is track successes & failures in different stages across my builds. Are there any alternatives to this approach?
You definitely could use Pipeline REST API Plugin, for me it was available out of the box with Jenkins 2.13.
By parsing the resulting JSON you could get the status of the stage similarly to what you expect. For the api call I personally use http_request plugin.
From the documentation GET /job/:job-name/:run-id/wfapi/describe returns:
{
"_links": {
"self": {
"href": "/jenkins/job/Test%20Workflow/16/wfapi/describe"
},
"pendingInputActions": {
"href": "/jenkins/job/Test%20Workflow/16/wfapi/pendingInputActions"
}
},
"id": "2014-10-16_13-07-52",
"name": "#16",
"status": "PAUSED_PENDING_INPUT",
"startTimeMillis": 1413461275770,
"endTimeMillis": 1413461285999,
"durationMillis": 10229,
"stages": [
{
"_links": {
"self": {
"href": "/jenkins/job/Test%20Workflow/16/execution/node/5/wfapi/describe"
}
},
"id": "5",
"name": "Build",
"status": "SUCCESS",
"startTimeMillis": 1413461275770,
"durationMillis": 5228
},
{
"_links": {
"self": {
"href": "/jenkins/job/Test%20Workflow/16/execution/node/8/wfapi/describe"
}
},
"id": "8",
"name": "Test",
"status": "SUCCESS",
"startTimeMillis": 1413461280998,
"durationMillis": 4994
},
{
"_links": {
"self": {
"href": "/jenkins/job/Test%20Workflow/16/execution/node/10/wfapi/describe"
}
},
"id": "10",
"name": "Deploy",
"status": "PAUSED_PENDING_INPUT",
"startTimeMillis": 1413461285992,
"durationMillis": 7
}
]
}
You can iterate all stages of the build and do what you need:
WorkflowRun run = Jenkins.instance.getItemByFullName("####YOUR_JOB_NAME####")._getRuns()[0]
FlowExecution exec = run.getExecution()
PipelineNodeGraphVisitor visitor = new PipelineNodeGraphVisitor(run)
def flowNodes = visitor.getPipelineNodes()
for (Iterator iterator = flowNodes.iterator(); iterator.hasNext();)
{
def node = iterator.next()
if (node.getType() == FlowNodeWrapper.NodeType.STAGE)
{
String stageName = node.getDisplayName()
def stageResult = node.getStatus().getResult()
println "Result of stage ${stageName} is ${stageResult}"
}
}
Here is a sample code to iterate all flow nodes and get whatever information you want:
import org.jenkinsci.plugins.workflow.graph.FlowGraphWalker
import org.jenkinsci.plugins.workflow.graph.FlowNode
try {
// just for demo, a success step and a failure step
node {
sh 'true'
sh 'false'
}
} finally {
FlowGraphWalker walker = new FlowGraphWalker(currentBuild.rawBuild.getExecution())
for (FlowNode flowNode: walker) {
// do whatever you want with flowNode
echo flowNode.dump()
}
}

Resources