Skip to content

Commit

Permalink
Merge pull request wso2#34 from anuruddhal/master
Browse files Browse the repository at this point in the history
Update samples to the new syntax
  • Loading branch information
isurulucky authored Jun 12, 2019
2 parents 21ecf75 + 63b1bf1 commit f184c85
Show file tree
Hide file tree
Showing 8 changed files with 433 additions and 414 deletions.
57 changes: 29 additions & 28 deletions hello-world-api/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,36 +26,37 @@ exposed as `global` API.
import ballerina/io;
import celleryio/cellery;
//Hello World Component
cellery:Component helloComponent = {
name: "hello-api",
source: {
image: "docker.io/wso2cellery/samples-hello-world-api"
},
ingresses: {
helloApi: <cellery:HttpApiIngress>{ port: 9090,
context: "hello",
definition: {
resources: [
{
path: "/",
method: "GET"
}
]
},
expose: "global"
public function build(cellery:ImageName iName) returns error? {
//Hello World Component
cellery:Component helloComponent = {
name: "hello-api",
source: {
image: "docker.io/wso2cellery/samples-hello-world-api-hello-service:0.2.0"
},
ingresses: {
helloApi: <cellery:HttpApiIngress>{ port: 9090,
context: "hello",
definition: {
resources: [
{
path: "/",
method: "GET"
}
]
},
expose: "global"
}
}
}
};
cellery:CellImage helloCell = {
components: {
helloComp: helloComponent
}
};
};
public function build(cellery:ImageName iName) returns error? {
return cellery:createImage(helloCell, iName);
cellery:CellImage helloCell = {
components: {
helloComp: helloComponent
}
};
//Build Hello Cell
io:println("Building Hello World Cell ...");
return cellery:createImage(helloCell, untaint iName);
}
```
---
Expand Down
57 changes: 29 additions & 28 deletions hello-world-api/hello-world-api.bal
Original file line number Diff line number Diff line change
Expand Up @@ -19,34 +19,35 @@
import ballerina/io;
import celleryio/cellery;

//Hello World Component
cellery:Component helloComponent = {
name: "hello-api",
source: {
image: "docker.io/wso2cellery/samples-hello-world-api-hello-service"
},
ingresses: {
helloApi: <cellery:HttpApiIngress>{ port: 9090,
context: "hello",
definition: {
resources: [
{
path: "/",
method: "GET"
}
]
},
expose: "global"
public function build(cellery:ImageName iName) returns error? {
//Hello World Component
cellery:Component helloComponent = {
name: "hello-api",
source: {
image: "docker.io/wso2cellery/samples-hello-world-api-hello-service:0.2.0"
},
ingresses: {
helloApi: <cellery:HttpApiIngress>{ port: 9090,
context: "hello",
definition: {
resources: [
{
path: "/",
method: "GET"
}
]
},
expose: "global"
}
}
}
};

cellery:CellImage helloCell = {
components: {
helloComp: helloComponent
}
};
};

public function build(cellery:ImageName iName) returns error? {
return cellery:createImage(helloCell, iName);
cellery:CellImage helloCell = {
components: {
helloComp: helloComponent
}
};
//Build Hello Cell
io:println("Building Hello World Cell ...");
return cellery:createImage(helloCell, untaint iName);
}
74 changes: 42 additions & 32 deletions hello-world/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,53 +25,63 @@ An environment variable `HELLO_NAME`with default value `Cellery` is used by `hel
env variable HELLO_NAME can be modified.

```ballerina
// Cell file for Hello world Sample
import ballerina/config;
import celleryio/cellery;
// Hello Component
// This Components exposes the HTML hello world page
cellery:Component helloComponent = {
name: "hello",
source: {
image: "wso2cellery/samples-hello-world-webapp"
},
ingresses: {
webUI: <cellery:WebIngress> { // Web ingress will be always exposed globally.
port: 80,
gatewayConfig: {
vhost: "hello-world.com",
context: "/"
# The Cellery Lifecycle Build method which is invoked for building the Cell Image.
#
# + iName - The Image name
# + return - The created Cell Image
public function build(cellery:ImageName iName) returns error? {
// Hello Component
// This Components exposes the HTML hello world page
cellery:Component helloComponent = {
name: "hello",
source: {
image: "wso2cellery/samples-hello-world-webapp:0.2.0"
},
ingresses: {
webUI: <cellery:WebIngress>{ // Web ingress will be always exposed globally.
port: 80,
gatewayConfig: {
vhost: "hello-world.com",
context: "/"
}
}
},
envVars: {
HELLO_NAME: { value: "Cellery" }
}
},
envVars: {
HELLO_NAME: {value: "Cellery"}
}
};
// Cell Initialization
cellery:CellImage helloCell = {
components: {
helloComp: helloComponent
}
};
};
public function build(cellery:ImageName iName) returns error? {
return cellery:createImage(helloCell, iName);
// Cell Initialization
cellery:CellImage helloCell = {
components: {
helloComp: helloComponent
}
};
return cellery:createImage(helloCell, untaint iName);
}
# The Cellery Lifecycle Run method which is invoked for creating a Cell Instance.
#
# + iName - The Image name
# + instances - The map dependency instances of the Cell instance to be created
# + return - The Cell instance
public function run(cellery:ImageName iName, map<cellery:ImageName> instances) returns error? {
cellery:CellImage helloCell = check cellery:constructCellImage(untaint iName);
string vhostName = config:getAsString("VHOST_NAME");
if (vhostName !== ""){
cellery:WebIngress web = <cellery:WebIngress> helloComponent.ingresses.webUI;
if (vhostName !== "") {
cellery:WebIngress web = <cellery:WebIngress>helloCell.components.helloComp.ingresses.webUI;
web.gatewayConfig.vhost = vhostName;
}
string helloName = config:getAsString("HELLO_NAME");
if (helloName !== ""){
helloComponent.envVars.HELLO_NAME.value = helloName;
if (helloName !== "") {
helloCell.components.helloComp.envVars.HELLO_NAME.value = helloName;
}
return cellery:createInstance(helloCell, iName);
return cellery:createInstance(helloCell, iName, instances);
}
```
---
Expand Down
73 changes: 41 additions & 32 deletions hello-world/hello-world.bal
Original file line number Diff line number Diff line change
Expand Up @@ -16,48 +16,57 @@
import ballerina/config;
import celleryio/cellery;

// Hello Component
// This Components exposes the HTML hello world page
cellery:Component helloComponent = {
name: "hello",
source: {
image: "wso2cellery/samples-hello-world-webapp"
},
ingresses: {
webUI: <cellery:WebIngress> { // Web ingress will be always exposed globally.
port: 80,
gatewayConfig: {
vhost: "hello-world.com",
context: "/"
# The Cellery Lifecycle Build method which is invoked for building the Cell Image.
#
# + iName - The Image name
# + return - The created Cell Image
public function build(cellery:ImageName iName) returns error? {
// Hello Component
// This Components exposes the HTML hello world page
cellery:Component helloComponent = {
name: "hello",
source: {
image: "wso2cellery/samples-hello-world-webapp:0.2.0"
},
ingresses: {
webUI: <cellery:WebIngress>{ // Web ingress will be always exposed globally.
port: 80,
gatewayConfig: {
vhost: "hello-world.com",
context: "/"
}
}
},
envVars: {
HELLO_NAME: { value: "Cellery" }
}
},
envVars: {
HELLO_NAME: {value: "Cellery"}
}
};

// Cell Initialization
cellery:CellImage helloCell = {
components: {
helloComp: helloComponent
}
};
};

public function build(cellery:ImageName iName) returns error? {
return cellery:createImage(helloCell, iName);
// Cell Initialization
cellery:CellImage helloCell = {
components: {
helloComp: helloComponent
}
};
return cellery:createImage(helloCell, untaint iName);
}

# The Cellery Lifecycle Run method which is invoked for creating a Cell Instance.
#
# + iName - The Image name
# + instances - The map dependency instances of the Cell instance to be created
# + return - The Cell instance
public function run(cellery:ImageName iName, map<cellery:ImageName> instances) returns error? {
cellery:CellImage helloCell = check cellery:constructCellImage(untaint iName);
string vhostName = config:getAsString("VHOST_NAME");
if (vhostName !== ""){
cellery:WebIngress web = <cellery:WebIngress> helloComponent.ingresses.webUI;
if (vhostName !== "") {
cellery:WebIngress web = <cellery:WebIngress>helloCell.components.helloComp.ingresses.webUI;
web.gatewayConfig.vhost = vhostName;
}

string helloName = config:getAsString("HELLO_NAME");
if (helloName !== ""){
helloComponent.envVars.HELLO_NAME.value = helloName;
if (helloName !== "") {
helloCell.components.helloComp.envVars.HELLO_NAME.value = helloName;
}
return cellery:createInstance(helloCell, iName);
return cellery:createInstance(helloCell, iName, instances);
}
Loading

0 comments on commit f184c85

Please sign in to comment.