Skip to content

Commit

Permalink
[CE-286] Necessary file for Deploying Fabric cluster
Browse files Browse the repository at this point in the history
1. Files under Resource dir will be shared among the Pods belong
to same Fabric cluster.
2. Template fils will be render to deployment file accroding to
the Fabric cluster information.

Change-Id: I35ba97acf2bbc9ad91295ecf897fc333bd66118d
Signed-off-by: luke <jiahaochen1993@gmail.com>
  • Loading branch information
jiahaoc1993 committed Apr 14, 2018
1 parent 99f3793 commit e07d543
Show file tree
Hide file tree
Showing 125 changed files with 2,775 additions and 0 deletions.
22 changes: 22 additions & 0 deletions src/agent/k8s/cluster_operations.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,14 @@ def _filter_cli_pod_name(self, namespace):
pod_list.append(i.metadata.name)
return pod_list

def _is_cluster_pods_running(self, namespace):
ret = self.corev1client.list_pod_for_all_namespaces(watch=False)
for i in ret.items:
if i.metadata.namespace == namespace:
if not i.status.phase == "Running":
return False
return True

def _get_cluster_pods(self, namespace):
ret = self.corev1client.list_pod_for_all_namespaces(watch=False)
pod_list = {}
Expand Down Expand Up @@ -458,6 +466,20 @@ def deploy_cluster(self, cluster_name, ports_index, nfsServer_ip):

self._deploy_cluster_resource(cluster_name, cluster_ports,
nfsServer_ip)

check_times = 0
while check_times < 10:
if self._is_cluster_pods_running(cluster_name):
break
logger.debug("Checking pods status...")
time.sleep(30)
check_times += 1

if check_times == 10:
logger.error("Failed to create cluster, the pods status is not "
"Running.")
return None

# Execute commands for cluster
self._setup_cluster(cluster_name)

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,199 @@
/*
Copyright IBM Corp. 2016 All Rights Reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package main

//WARNING - this chaincode's ID is hard-coded in chaincode_example04 to illustrate one way of
//calling chaincode from a chaincode. If this example is modified, chaincode_example04.go has
//to be modified as well with the new ID of chaincode_example02.
//chaincode_example05 show's how chaincode ID can be passed in as a parameter instead of
//hard-coding.

import (
"fmt"
"strconv"

"github.com/hyperledger/fabric/core/chaincode/shim"
pb "github.com/hyperledger/fabric/protos/peer"
)

// SimpleChaincode example simple Chaincode implementation
type SimpleChaincode struct {
}

func (t *SimpleChaincode) Init(stub shim.ChaincodeStubInterface) pb.Response {
fmt.Println("ex02 Init")
_, args := stub.GetFunctionAndParameters()
var A, B string // Entities
var Aval, Bval int // Asset holdings
var err error

if len(args) != 4 {
return shim.Error("Incorrect number of arguments. Expecting 4")
}

// Initialize the chaincode
A = args[0]
Aval, err = strconv.Atoi(args[1])
if err != nil {
return shim.Error("Expecting integer value for asset holding")
}
B = args[2]
Bval, err = strconv.Atoi(args[3])
if err != nil {
return shim.Error("Expecting integer value for asset holding")
}
fmt.Printf("Aval = %d, Bval = %d\n", Aval, Bval)

// Write the state to the ledger
err = stub.PutState(A, []byte(strconv.Itoa(Aval)))
if err != nil {
return shim.Error(err.Error())
}

err = stub.PutState(B, []byte(strconv.Itoa(Bval)))
if err != nil {
return shim.Error(err.Error())
}

return shim.Success(nil)
}

func (t *SimpleChaincode) Invoke(stub shim.ChaincodeStubInterface) pb.Response {
fmt.Println("ex02 Invoke")
function, args := stub.GetFunctionAndParameters()
if function == "invoke" {
// Make payment of X units from A to B
return t.invoke(stub, args)
} else if function == "delete" {
// Deletes an entity from its state
return t.delete(stub, args)
} else if function == "query" {
// the old "Query" is now implemtned in invoke
return t.query(stub, args)
}

return shim.Error("Invalid invoke function name. Expecting \"invoke\" \"delete\" \"query\"")
}

// Transaction makes payment of X units from A to B
func (t *SimpleChaincode) invoke(stub shim.ChaincodeStubInterface, args []string) pb.Response {
var A, B string // Entities
var Aval, Bval int // Asset holdings
var X int // Transaction value
var err error

if len(args) != 3 {
return shim.Error("Incorrect number of arguments. Expecting 3")
}

A = args[0]
B = args[1]

// Get the state from the ledger
// TODO: will be nice to have a GetAllState call to ledger
Avalbytes, err := stub.GetState(A)
if err != nil {
return shim.Error("Failed to get state")
}
if Avalbytes == nil {
return shim.Error("Entity not found")
}
Aval, _ = strconv.Atoi(string(Avalbytes))

Bvalbytes, err := stub.GetState(B)
if err != nil {
return shim.Error("Failed to get state")
}
if Bvalbytes == nil {
return shim.Error("Entity not found")
}
Bval, _ = strconv.Atoi(string(Bvalbytes))

// Perform the execution
X, err = strconv.Atoi(args[2])
if err != nil {
return shim.Error("Invalid transaction amount, expecting a integer value")
}
Aval = Aval - X
Bval = Bval + X
fmt.Printf("Aval = %d, Bval = %d\n", Aval, Bval)

// Write the state back to the ledger
err = stub.PutState(A, []byte(strconv.Itoa(Aval)))
if err != nil {
return shim.Error(err.Error())
}

err = stub.PutState(B, []byte(strconv.Itoa(Bval)))
if err != nil {
return shim.Error(err.Error())
}

return shim.Success(nil)
}

// Deletes an entity from state
func (t *SimpleChaincode) delete(stub shim.ChaincodeStubInterface, args []string) pb.Response {
if len(args) != 1 {
return shim.Error("Incorrect number of arguments. Expecting 1")
}

A := args[0]

// Delete the key from the state in ledger
err := stub.DelState(A)
if err != nil {
return shim.Error("Failed to delete state")
}

return shim.Success(nil)
}

// query callback representing the query of a chaincode
func (t *SimpleChaincode) query(stub shim.ChaincodeStubInterface, args []string) pb.Response {
var A string // Entities
var err error

if len(args) != 1 {
return shim.Error("Incorrect number of arguments. Expecting name of the person to query")
}

A = args[0]

// Get the state from the ledger
Avalbytes, err := stub.GetState(A)
if err != nil {
jsonResp := "{\"Error\":\"Failed to get state for " + A + "\"}"
return shim.Error(jsonResp)
}

if Avalbytes == nil {
jsonResp := "{\"Error\":\"Nil amount for " + A + "\"}"
return shim.Error(jsonResp)
}

jsonResp := "{\"Name\":\"" + A + "\",\"Amount\":\"" + string(Avalbytes) + "\"}"
fmt.Printf("Query Response:%s\n", jsonResp)
return shim.Success(Avalbytes)
}

func main() {
err := shim.Start(new(SimpleChaincode))
if err != nil {
fmt.Printf("Error starting Simple chaincode: %s", err)
}
}
Binary file not shown.
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
---
Profiles:

OrdererGenesis:
Orderer:
<<: *OrdererDefaults
Organizations:
- *OrdererOrg
Consortiums:
SampleConsortium:
Organizations:
- *Org2
- *Org1
DefaultChannel:
Consortium: SampleConsortium
Application:
<<: *ApplicationDefaults
Organizations:
- *Org2
- *Org1

################################################################################
# Section: Organizations
################################################################################
Organizations:
- &OrdererOrg
#Name: OrdererOrgMSP
#ID: OrdererOrgMSP
Name: OrdererMSP
ID: OrdererMSP
MSPDir: crypto-config/ordererOrganizations/ordererorg/msp

- &Org2
Name: Org2MSP
ID: Org2MSP
MSPDir: crypto-config/peerOrganizations/org2/msp
AnchorPeers:
#- Host: peer0.Org2
- Host: peer0-org2
Port: 7051
- &Org1
Name: Org1MSP
ID: Org1MSP
MSPDir: crypto-config/peerOrganizations/org1/msp
AnchorPeers:
#- Host: peer0.Org1
- Host: peer0-org1
Port: 7051

################################################################################
# SECTION: Orderer
################################################################################
Orderer: &OrdererDefaults
OrdererType: solo
Addresses:
#- orderer0.ordererorg:7050
- orderer0:7050
Kafka:
Brokers:
BatchTimeout: 2s
BatchSize:
MaxMessageCount: 10
AbsoluteMaxBytes: 98 MB
PreferredMaxBytes: 512 KB
Organizations:

################################################################################
# SECTION: Application
################################################################################
Application: &ApplicationDefaults
Organizations:
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
-----BEGIN CERTIFICATE-----
MIICKzCCAdKgAwIBAgIRAIcX/S5EiiJ1OIlM25uLnAEwCgYIKoZIzj0EAwIwZzEL
MAkGA1UEBhMCVVMxEzARBgNVBAgTCkNhbGlmb3JuaWExFjAUBgNVBAcTDVNhbiBG
cmFuY2lzY28xEzARBgNVBAoTCm9yZGVyZXJvcmcxFjAUBgNVBAMTDWNhLm9yZGVy
ZXJvcmcwHhcNMTgwNDA1MTU0NDA1WhcNMjgwNDAyMTU0NDA1WjBnMQswCQYDVQQG
EwJVUzETMBEGA1UECBMKQ2FsaWZvcm5pYTEWMBQGA1UEBxMNU2FuIEZyYW5jaXNj
bzETMBEGA1UEChMKb3JkZXJlcm9yZzEWMBQGA1UEAxMNY2Eub3JkZXJlcm9yZzBZ
MBMGByqGSM49AgEGCCqGSM49AwEHA0IABG6lPdbHKzmbQVXvVYKo8I6erTi6unr7
/de0ivsSZddrMhmLmy0rHaU4tlM3Iudvir15tROfEMYMCjqEUaCe3hujXzBdMA4G
A1UdDwEB/wQEAwIBpjAPBgNVHSUECDAGBgRVHSUAMA8GA1UdEwEB/wQFMAMBAf8w
KQYDVR0OBCIEIMqm7RMTfzS7rpWdNN/lo1vgzgmYxJDKVfWL8zbzD6i8MAoGCCqG
SM49BAMCA0cAMEQCICSljDFEd3Eek/Uw7hZRRpGcYcDBSLX9Q35pwLR3/9cyAiAo
2w4ol5/1nkmaKyM6kZaRPmaMIBLZaBIRIsYzQvS3EQ==
-----END CERTIFICATE-----
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
-----BEGIN PRIVATE KEY-----
MIGHAgEAMBMGByqGSM49AgEGCCqGSM49AwEHBG0wawIBAQQgJhcu5BIuWoW/r3gv
I3nBDgof2neHY8vX+ZY994bzyiyhRANCAARupT3Wxys5m0FV71WCqPCOnq04urp6
+/3XtIr7EmXXazIZi5stKx2lOLZTNyLnb4q9ebUTnxDGDAo6hFGgnt4b
-----END PRIVATE KEY-----
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
-----BEGIN CERTIFICATE-----
MIICCDCCAa6gAwIBAgIRAMhn0nq2GeTis/NKhpEYwX0wCgYIKoZIzj0EAwIwZzEL
MAkGA1UEBhMCVVMxEzARBgNVBAgTCkNhbGlmb3JuaWExFjAUBgNVBAcTDVNhbiBG
cmFuY2lzY28xEzARBgNVBAoTCm9yZGVyZXJvcmcxFjAUB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wIDSAAwRQIhAMWab6Qg+Jc2JG8quBz4n+iF2nYivuXoIhdE3oRX
qVUoAiBVJtZAi6dy3CV5w8/OpBJq6x5zySGbGqjaNZ9SLvIkYw==
-----END CERTIFICATE-----
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
-----BEGIN CERTIFICATE-----
MIICCDCCAa6gAwIBAgIRAMhn0nq2GeTis/NKhpEYwX0wCgYIKoZIzj0EAwIwZzEL
MAkGA1UEBhMCVVMxEzARBgNVBAgTCkNhbGlmb3JuaWExFjAUBgNVBAcTDVNhbiBG
cmFuY2lzY28xEzARBgNVBAoTCm9yZGVyZXJvcmcxFjAUBgNVBAMTDWNhLm9yZGVy
ZXJvcmcwHhcNMTgwNDA1MTU0NDA1WhcNMjgwNDAyMTU0NDA1WjBVMQswCQYDVQQG
EwJVUzETMBEGA1UECBMKQ2FsaWZvcm5pYTEWMBQGA1UEBxMNU2FuIEZyYW5jaXNj
bzEZMBcGA1UEAwwQQWRtaW5Ab3JkZXJlcm9yZzBZMBMGByqGSM49AgEGCCqGSM49
AwEHA0IABOAu9HUPl74StuOjflYh1vIYlBx8DMGsxfm2O6c106p8kxT0d2Anm+B6
k4oHw2VKT3goqt1BJ6KAUn0tG+mHqr2jTTBLMA4GA1UdDwEB/wQEAwIHgDAMBgNV
HRMBAf8EAjAAMCsGA1UdIwQkMCKAIMqm7RMTfzS7rpWdNN/lo1vgzgmYxJDKVfWL
8zbzD6i8MAoGCCqGSM49BAMCA0gAMEUCIQD+Nj5t5lOdXaDi6D/EGrT8iAnCf0FQ
n/jxcVfyn3XSvQIgVLOf5J2J6E0G6Y/lDzZwpTrx91jHSGyqttcsvmF9oA8=
-----END CERTIFICATE-----
Loading

0 comments on commit e07d543

Please sign in to comment.