From 57fd2b377635a45daa653b5c1d52a64f85ee9524 Mon Sep 17 00:00:00 2001 From: Mark Ryan Date: Mon, 27 Jun 2016 15:49:35 +0100 Subject: [PATCH] ciao-launcher: refactor instance go routine code The code for the instance go routine is split over a number of different files. These files have been renamed to make it obvious in which context their code runs. Code that is not unique to the instance go routine, i.e., the error types for specific commands has been moved to new files. Fixes: #10 Signed-off-by: Mark Ryan --- ciao-launcher/delete_error.go | 45 +++++++++++++++++++ .../{delete.go => delete_instance.go} | 24 ---------- ciao-launcher/restart_error.go | 45 +++++++++++++++++++ .../{restart.go => restart_instance.go} | 23 ---------- ciao-launcher/start_error.go | 45 +++++++++++++++++++ ciao-launcher/{start.go => start_instance.go} | 23 ---------- ciao-launcher/{stop.go => stop_error.go} | 0 7 files changed, 135 insertions(+), 70 deletions(-) create mode 100644 ciao-launcher/delete_error.go rename ciao-launcher/{delete.go => delete_instance.go} (76%) create mode 100644 ciao-launcher/restart_error.go rename ciao-launcher/{restart.go => restart_instance.go} (73%) create mode 100644 ciao-launcher/start_error.go rename ciao-launcher/{start.go => start_instance.go} (89%) rename ciao-launcher/{stop.go => stop_error.go} (100%) diff --git a/ciao-launcher/delete_error.go b/ciao-launcher/delete_error.go new file mode 100644 index 000000000..6a1d7f5d3 --- /dev/null +++ b/ciao-launcher/delete_error.go @@ -0,0 +1,45 @@ +/* +// Copyright (c) 2016 Intel Corporation +// +// 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 + +import ( + "github.com/01org/ciao/payloads" + "github.com/01org/ciao/ssntp" + "github.com/golang/glog" +) + +type deleteError struct { + err error + code payloads.DeleteFailureReason +} + +func (de *deleteError) send(conn serverConn, instance string) { + if !conn.isConnected() { + return + } + + payload, err := generateDeleteError(instance, de) + if err != nil { + glog.Errorf("Unable to generate payload for delete_failure: %v", err) + return + } + + _, err = conn.SendError(ssntp.DeleteFailure, payload) + if err != nil { + glog.Errorf("Unable to send delete_failure: %v", err) + } +} diff --git a/ciao-launcher/delete.go b/ciao-launcher/delete_instance.go similarity index 76% rename from ciao-launcher/delete.go rename to ciao-launcher/delete_instance.go index 178c45035..6fe8e4161 100644 --- a/ciao-launcher/delete.go +++ b/ciao-launcher/delete_instance.go @@ -19,33 +19,9 @@ package main import ( "os" - "github.com/01org/ciao/payloads" - "github.com/01org/ciao/ssntp" "github.com/golang/glog" ) -type deleteError struct { - err error - code payloads.DeleteFailureReason -} - -func (de *deleteError) send(conn serverConn, instance string) { - if !conn.isConnected() { - return - } - - payload, err := generateDeleteError(instance, de) - if err != nil { - glog.Errorf("Unable to generate payload for delete_failure: %v", err) - return - } - - _, err = conn.SendError(ssntp.DeleteFailure, payload) - if err != nil { - glog.Errorf("Unable to send delete_failure: %v", err) - } -} - func deleteVnic(instanceDir string, conn serverConn) { cfg, err := loadVMConfig(instanceDir) if err != nil { diff --git a/ciao-launcher/restart_error.go b/ciao-launcher/restart_error.go new file mode 100644 index 000000000..4540514d4 --- /dev/null +++ b/ciao-launcher/restart_error.go @@ -0,0 +1,45 @@ +/* +// Copyright (c) 2016 Intel Corporation +// +// 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 + +import ( + "github.com/01org/ciao/payloads" + "github.com/01org/ciao/ssntp" + "github.com/golang/glog" +) + +type restartError struct { + err error + code payloads.RestartFailureReason +} + +func (re *restartError) send(conn serverConn, instance string) { + if !conn.isConnected() { + return + } + + payload, err := generateRestartError(instance, re) + if err != nil { + glog.Errorf("Unable to generate payload for restart_failure: %v", err) + return + } + + _, err = conn.SendError(ssntp.RestartFailure, payload) + if err != nil { + glog.Errorf("Unable to send restart_failure: %v", err) + } +} diff --git a/ciao-launcher/restart.go b/ciao-launcher/restart_instance.go similarity index 73% rename from ciao-launcher/restart.go rename to ciao-launcher/restart_instance.go index 97956772c..50e6c1422 100644 --- a/ciao-launcher/restart.go +++ b/ciao-launcher/restart_instance.go @@ -19,32 +19,9 @@ package main import ( "github.com/01org/ciao/networking/libsnnet" "github.com/01org/ciao/payloads" - "github.com/01org/ciao/ssntp" "github.com/golang/glog" ) -type restartError struct { - err error - code payloads.RestartFailureReason -} - -func (re *restartError) send(conn serverConn, instance string) { - if !conn.isConnected() { - return - } - - payload, err := generateRestartError(instance, re) - if err != nil { - glog.Errorf("Unable to generate payload for restart_failure: %v", err) - return - } - - _, err = conn.SendError(ssntp.RestartFailure, payload) - if err != nil { - glog.Errorf("Unable to send restart_failure: %v", err) - } -} - func processRestart(instanceDir string, vm virtualizer, conn serverConn, cfg *vmConfig) *restartError { var vnicName string var vnicCfg *libsnnet.VnicConfig diff --git a/ciao-launcher/start_error.go b/ciao-launcher/start_error.go new file mode 100644 index 000000000..25cbc0e14 --- /dev/null +++ b/ciao-launcher/start_error.go @@ -0,0 +1,45 @@ +/* +// Copyright (c) 2016 Intel Corporation +// +// 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 + +import ( + "github.com/01org/ciao/payloads" + "github.com/01org/ciao/ssntp" + "github.com/golang/glog" +) + +type startError struct { + err error + code payloads.StartFailureReason +} + +func (se *startError) send(conn serverConn, instance string) { + if !conn.isConnected() { + return + } + + payload, err := generateStartError(instance, se) + if err != nil { + glog.Errorf("Unable to generate payload for start_failure: %v", err) + return + } + + _, err = conn.SendError(ssntp.StartFailure, payload) + if err != nil { + glog.Errorf("Unable to send start_failure: %v", err) + } +} diff --git a/ciao-launcher/start.go b/ciao-launcher/start_instance.go similarity index 89% rename from ciao-launcher/start.go rename to ciao-launcher/start_instance.go index 3af8aa1ba..8cd006cab 100644 --- a/ciao-launcher/start.go +++ b/ciao-launcher/start_instance.go @@ -25,15 +25,9 @@ import ( "github.com/01org/ciao/networking/libsnnet" "github.com/01org/ciao/payloads" - "github.com/01org/ciao/ssntp" "github.com/golang/glog" ) -type startError struct { - err error - code payloads.StartFailureReason -} - type startTimes struct { startStamp time.Time backingImageCheck time.Time @@ -42,23 +36,6 @@ type startTimes struct { runStamp time.Time } -func (se *startError) send(conn serverConn, instance string) { - if !conn.isConnected() { - return - } - - payload, err := generateStartError(instance, se) - if err != nil { - glog.Errorf("Unable to generate payload for start_failure: %v", err) - return - } - - _, err = conn.SendError(ssntp.StartFailure, payload) - if err != nil { - glog.Errorf("Unable to send start_failure: %v", err) - } -} - func ensureBackingImage(vm virtualizer) error { err := vm.checkBackingImage() diff --git a/ciao-launcher/stop.go b/ciao-launcher/stop_error.go similarity index 100% rename from ciao-launcher/stop.go rename to ciao-launcher/stop_error.go