2016-11-18 21:40:15 +01:00
|
|
|
// Copyright 2016 Marapongo, Inc. All rights reserved.
|
|
|
|
|
|
|
|
package backends
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/marapongo/mu/pkg/compiler/backends/clouds"
|
|
|
|
"github.com/marapongo/mu/pkg/compiler/backends/clouds/aws"
|
|
|
|
"github.com/marapongo/mu/pkg/compiler/backends/schedulers"
|
2016-11-22 21:37:14 +01:00
|
|
|
"github.com/marapongo/mu/pkg/compiler/backends/schedulers/awsecs"
|
2016-11-18 21:40:15 +01:00
|
|
|
"github.com/marapongo/mu/pkg/compiler/core"
|
2016-11-19 20:28:40 +01:00
|
|
|
"github.com/marapongo/mu/pkg/diag"
|
2016-11-20 01:13:13 +01:00
|
|
|
"github.com/marapongo/mu/pkg/util"
|
2016-11-18 21:40:15 +01:00
|
|
|
)
|
|
|
|
|
2016-11-19 20:28:40 +01:00
|
|
|
func New(arch Arch, d diag.Sink) core.Backend {
|
2016-11-22 21:37:14 +01:00
|
|
|
// Bind to the cloud provider.
|
|
|
|
var cloud clouds.Cloud
|
2016-11-18 21:40:15 +01:00
|
|
|
switch arch.Cloud {
|
2016-11-22 21:37:14 +01:00
|
|
|
case clouds.AWS:
|
2016-12-03 00:00:44 +01:00
|
|
|
// TODO(joe): come up with a way to get options from CLI/workspace/etc. to here.
|
|
|
|
cloud = aws.New(d, aws.Options{})
|
2016-11-22 21:37:14 +01:00
|
|
|
case clouds.None:
|
2016-12-03 02:07:15 +01:00
|
|
|
util.FailM("Expected a non-None cloud architecture")
|
2016-11-18 21:40:15 +01:00
|
|
|
default:
|
2016-11-20 01:13:13 +01:00
|
|
|
util.FailMF("Cloud architecture '%v' not yet supported", clouds.Names[arch.Cloud])
|
2016-11-18 21:40:15 +01:00
|
|
|
}
|
2016-11-22 21:37:14 +01:00
|
|
|
util.Assert(cloud != nil)
|
|
|
|
util.Assert(cloud.Arch() == arch.Cloud)
|
|
|
|
|
|
|
|
// Set the backend to the cloud provider.
|
|
|
|
var be core.Backend = cloud
|
2016-11-18 21:40:15 +01:00
|
|
|
|
2016-11-22 21:37:14 +01:00
|
|
|
// Now bind to the scheduler, if any, wrapping the cloud and replacing the backend.
|
|
|
|
var scheduler schedulers.Scheduler
|
2016-11-18 21:40:15 +01:00
|
|
|
switch arch.Scheduler {
|
2016-11-22 21:37:14 +01:00
|
|
|
case schedulers.None:
|
2016-11-18 21:40:15 +01:00
|
|
|
// Nothing to do.
|
2016-11-22 21:37:14 +01:00
|
|
|
case schedulers.AWSECS:
|
|
|
|
scheduler = awsecs.New(d, cloud)
|
2016-11-18 21:40:15 +01:00
|
|
|
default:
|
2016-11-20 01:13:13 +01:00
|
|
|
util.FailMF("Scheduler architecture '%v' not yet supported", schedulers.Names[arch.Scheduler])
|
2016-11-18 21:40:15 +01:00
|
|
|
}
|
2016-11-22 21:37:14 +01:00
|
|
|
if scheduler != nil {
|
|
|
|
util.Assert(scheduler.Arch() == arch.Scheduler)
|
|
|
|
be = scheduler
|
|
|
|
}
|
2016-11-18 21:40:15 +01:00
|
|
|
|
|
|
|
return be
|
|
|
|
}
|