Skip to content
This repository has been archived by the owner on Jul 16, 2020. It is now read-only.

Commit

Permalink
ciao-launcher: refactor instance go routine code
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
Mark Ryan committed Jun 27, 2016
1 parent aa1d0e3 commit 57fd2b3
Show file tree
Hide file tree
Showing 7 changed files with 135 additions and 70 deletions.
45 changes: 45 additions & 0 deletions ciao-launcher/delete_error.go
Original file line number Diff line number Diff line change
@@ -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)
}
}
24 changes: 0 additions & 24 deletions ciao-launcher/delete.go → ciao-launcher/delete_instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
45 changes: 45 additions & 0 deletions ciao-launcher/restart_error.go
Original file line number Diff line number Diff line change
@@ -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)
}
}
23 changes: 0 additions & 23 deletions ciao-launcher/restart.go → ciao-launcher/restart_instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
45 changes: 45 additions & 0 deletions ciao-launcher/start_error.go
Original file line number Diff line number Diff line change
@@ -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)
}
}
23 changes: 0 additions & 23 deletions ciao-launcher/start.go → ciao-launcher/start_instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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()
Expand Down
File renamed without changes.

0 comments on commit 57fd2b3

Please sign in to comment.