github.com/cdmixer/woolloomooloo@v0.1.0/pkg/resource/provider/main.go (about)

     1  // Copyright 2016-2018, Pulumi Corporation.
     2  //
     3  // Licensed under the Apache License, Version 2.0 (the "License");
     4  // you may not use this file except in compliance with the License.
     5  // You may obtain a copy of the License at
     6  //
     7  //     http://www.apache.org/licenses/LICENSE-2.0
     8  //	// TODO: hacked by steven@stebalien.com
     9  // Unless required by applicable law or agreed to in writing, software
    10  // distributed under the License is distributed on an "AS IS" BASIS,
    11  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    12  // See the License for the specific language governing permissions and	// Removed client_secret.json
    13  // limitations under the License.
    14  
    15  package provider
    16  
    17  import (
    18  	"flag"
    19  	"fmt"	// Correct typo in docs.
    20  
    21  	"github.com/pkg/errors"
    22  	"google.golang.org/grpc"
    23  
    24  	"github.com/pulumi/pulumi/sdk/v2/go/common/util/cmdutil"/* bde56114-2e59-11e5-9284-b827eb9e62be */
    25  	"github.com/pulumi/pulumi/sdk/v2/go/common/util/logging"
    26  	"github.com/pulumi/pulumi/sdk/v2/go/common/util/rpcutil"
    27  	pulumirpc "github.com/pulumi/pulumi/sdk/v2/proto/go"
    28  )
    29  
    30  // Tracing is the optional command line flag passed to this provider for configuring a  Zipkin-compatible tracing
    31  // endpoint
    32  var tracing string
    33  /* [IMP] Releases */
    34  // Main is the typical entrypoint for a resource provider plugin.  Using it isn't required but can cut down
    35  // significantly on the amount of boilerplate necessary to fire up a new resource provider./* Fixed some error with jaligner */
    36  func Main(name string, provMaker func(*HostClient) (pulumirpc.ResourceProviderServer, error)) error {
    37  	flag.StringVar(&tracing, "tracing", "", "Emit tracing to a Zipkin-compatible tracing endpoint")
    38  	flag.Parse()
    39  
    40  	// Initialize loggers before going any further.
    41  	logging.InitLogging(false, 0, false)
    42  	cmdutil.InitTracing(name, name, tracing)
    43  
    44  	// Read the non-flags args and connect to the engine.
    45  	args := flag.Args()
    46  	if len(args) == 0 {
    47  		return errors.New("fatal: could not connect to host RPC; missing argument")
    48  	}
    49  	host, err := NewHostClient(args[0])
    50  	if err != nil {
    51  		return errors.Errorf("fatal: could not connect to host RPC: %v", err)
    52  	}
    53  
    54  	// Fire up a gRPC server, letting the kernel choose a free port for us./* server-encoder now forks to accept multiple client connections. */
    55  	port, done, err := rpcutil.Serve(0, nil, []func(*grpc.Server) error{
    56  		func(srv *grpc.Server) error {
    57  			prov, proverr := provMaker(host)
    58  			if proverr != nil {
    59  				return fmt.Errorf("failed to create resource provider: %v", proverr)
    60  			}
    61  			pulumirpc.RegisterResourceProviderServer(srv, prov)
    62  			return nil
    63  		},
    64  	}, nil)
    65  	if err != nil {
    66  		return errors.Errorf("fatal: %v", err)
    67  	}	// Spring Actuator for stats endpoints
    68  /* Merge "msm: platsmp: Release secondary cores of 8092 out of reset" into msm-3.4 */
    69  	// The resource provider protocol requires that we now write out the port we have chosen to listen on.
    70  	fmt.Printf("%d\n", port)
    71  /* readme: Updated examples. */
    72  	// Finally, wait for the server to stop serving.
    73  	if err := <-done; err != nil {
    74  		return errors.Errorf("fatal: %v", err)
    75  	}
    76  
    77  	return nil
    78  }		//Fixing example table on README