Skip to content
Snippets Groups Projects
Commit 28c06bf6 authored by Malte Bauch's avatar Malte Bauch
Browse files

Add remove method to plugin

parent 87808c33
Branches master
No related tags found
No related merge requests found
......@@ -392,7 +392,7 @@ func shutdown() error {
}
for _, plugin := range plugins {
log.Info("Defer: ", plugin.Manifest().Name)
plugin.GetClient().Kill()
plugin.Close()
log.Info("Defer - exited: ", plugin.GetClient().Exited())
}
coreLock.Unlock()
......
......@@ -46,6 +46,7 @@ type Plugin interface {
Ping() error
Restart() error
Close()
Remove() error
shared.DeviceModel
}
......
......@@ -723,32 +723,43 @@ func (n *NetworkElementServer) addMne(ctx context.Context, name string, opt *tpb
mne, err := nucleus.NewNetworkElement(name, networkElementID, opt, pndID, plugin, conflict.Metadata{ResourceVersion: 0})
if err != nil {
plugin.Remove()
return uuid.Nil, err
}
if mne.IsTransportValid() {
resp, err := n.getPath(ctx, mne, "/")
if err != nil {
plugin.Remove()
return uuid.Nil, err
}
err = mne.ProcessResponse(resp)
if err != nil {
plugin.Remove()
return uuid.Nil, err
}
err = n.mneService.Add(mne)
if err != nil {
plugin.Remove()
return uuid.Nil, err
}
err = n.pluginService.Add(plugin)
if err != nil {
if err := plugin.Remove(); err != nil {
return uuid.Nil, status.Errorf(codes.Internal, "failed to clean up plugin: ", err)
}
if err := n.mneService.Delete(mne); err != nil {
return uuid.Nil, status.Errorf(codes.Internal, "failed to clean up device: ", err)
}
return uuid.Nil, err
}
n.networkElementWatchter.SubscribeToNetworkElement(mne, config.GetGnmiSubscriptionPaths(), nil)
} else {
plugin.Remove()
return uuid.Nil, status.Errorf(codes.InvalidArgument, "invalid transport data provided")
}
......
......@@ -3,6 +3,7 @@ package nucleus
import (
"encoding/json"
"fmt"
"os"
"os/exec"
"path/filepath"
......@@ -129,6 +130,15 @@ func (p *Plugin) ReattachConfig() *hcplugin.ReattachConfig {
return p.client.ReattachConfig()
}
// Remove ensures that the Plugin is killed and the corresponding files are
// removed.
func (p *Plugin) Remove() error {
// stop the running plugins process
p.Close()
// remove the plugins folder
return os.RemoveAll(p.ExecPath())
}
// State returns the current state of the plugin.
// Different states of the plugin can be:
// - created
......@@ -165,6 +175,7 @@ func (p *Plugin) Restart() error {
// Close ends the execution of the plugin.
func (p *Plugin) Close() {
// end the plugin process
p.client.Kill()
}
......
......@@ -106,7 +106,7 @@ func (s *PluginService) Delete(pluginToDelete plugin.Plugin) error {
}
// stop the plugin
pluginToDelete.GetClient().Kill()
pluginToDelete.Close()
if err := s.eventService.PublishEvent(PluginEventTopic, event.NewDeleteEvent(pluginToDelete.ID())); err != nil {
log.Error(err)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment