Skip to content
This repository has been archived by the owner on Jan 20, 2023. It is now read-only.

Commit

Permalink
Naming convention (#49)
Browse files Browse the repository at this point in the history
Make broker download metas using new naming convention
Details at eclipse-che/che-plugin-registry#55
Signed-off-by: Oleksandr Garagatyi <ogaragat@redhat.com>
  • Loading branch information
Oleksandr Garagatyi authored Apr 24, 2019
1 parent e93ad4d commit c90e7d4
Show file tree
Hide file tree
Showing 14 changed files with 304 additions and 221 deletions.
3 changes: 1 addition & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,7 @@ test-local:
--disable-push \
--runtime-id wsId:env:ownerId \
--registry-address https://che-plugin-registry.openshift.io \
--metas ./config-plugin-ids.json \
--download-metas
--metas ./config-plugin-ids.json

.PHONY: test-local-legacy
test-local-legacy:
Expand Down
14 changes: 7 additions & 7 deletions brokers/che-plugin-broker/broker.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ func (cheBroker *chePluginBrokerImpl) PushEvents(tun *jsonrpc.Tunnel) {
}

func (cheBroker *chePluginBrokerImpl) ProcessPlugin(meta model.PluginMeta) error {
cheBroker.PrintDebug("Stared processing plugin '%s:%s'", meta.ID, meta.Version)
cheBroker.PrintDebug("Stared processing plugin '%s'", meta.ID)
url := meta.URL

switch getTypeOfURL(url) {
Expand All @@ -139,13 +139,13 @@ func (cheBroker *chePluginBrokerImpl) processYAML(meta *model.PluginMeta, url st
}

chePluginYamlPath := filepath.Join(workDir, pluginFileName)
cheBroker.PrintDebug("Downloading plugin definition '%s' for plugin '%s:%s' to '%s'", url, meta.ID, meta.Version, chePluginYamlPath)
cheBroker.PrintDebug("Downloading plugin definition '%s' for plugin '%s' to '%s'", url, meta.ID, chePluginYamlPath)
err = cheBroker.ioUtil.Download(url, chePluginYamlPath)
if err != nil {
return err
}

cheBroker.PrintDebug("Resolving '%s:%s'", meta.ID, meta.Version)
cheBroker.PrintDebug("Resolving '%s'", meta.ID)
err = cheBroker.resolveToolingConfig(meta, workDir)
if err != nil {
return err
Expand All @@ -162,20 +162,20 @@ func (cheBroker *chePluginBrokerImpl) processArchive(meta *model.PluginMeta, url
pluginPath := filepath.Join(workDir, "plugin")

// Download an archive
cheBroker.PrintDebug("Downloading archive '%s' for plugin '%s:%s' to '%s'", url, meta.ID, meta.Version, archivePath)
cheBroker.PrintDebug("Downloading archive '%s' for plugin '%s' to '%s'", url, meta.ID, archivePath)
err = cheBroker.ioUtil.Download(url, archivePath)
if err != nil {
return err
}

// Untar it
cheBroker.PrintDebug("Untarring archive '%s' for plugin '%s:%s' to '%s'", url, meta.ID, meta.Version, archivePath)
cheBroker.PrintDebug("Unpacking archive '%s' for plugin '%s' to '%s'", url, meta.ID, archivePath)
err = cheBroker.ioUtil.Untar(archivePath, pluginPath)
if err != nil {
return err
}

cheBroker.PrintDebug("Resolving '%s:%s'", meta.ID, meta.Version)
cheBroker.PrintDebug("Resolving '%s'", meta.ID)
err = cheBroker.resolveToolingConfig(meta, pluginPath)
if err != nil {
return err
Expand All @@ -185,7 +185,7 @@ func (cheBroker *chePluginBrokerImpl) processArchive(meta *model.PluginMeta, url
return nil
}

cheBroker.PrintDebug("Copying dependencies for '%s:%s'", meta.ID, meta.Version)
cheBroker.PrintDebug("Copying dependencies for '%s'", meta.ID)
return cheBroker.copyDependencies(pluginPath)
}

Expand Down
2 changes: 2 additions & 0 deletions brokers/che-plugin-broker/broker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,7 @@ func TestProcessPlugin(t *testing.T) {
{
ID: meta.ID,
Version: meta.Version,
Name: meta.Name,
Endpoints: toolingConf.Endpoints,
Containers: toolingConf.Containers,
Editors: toolingConf.Editors,
Expand Down Expand Up @@ -321,6 +322,7 @@ func TestProcessPluginWithYaml(t *testing.T) {
{
ID: meta.ID,
Version: meta.Version,
Name: meta.Name,
Endpoints: toolingConf.Endpoints,
Containers: toolingConf.Containers,
Editors: toolingConf.Editors,
Expand Down
14 changes: 7 additions & 7 deletions brokers/theia/broker.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ func (b *brokerImpl) PushEvents(tun *jsonrpc.Tunnel) {
}

func (b *brokerImpl) ProcessPlugin(meta model.PluginMeta) error {
b.PrintDebug("Stared processing plugin '%s:%s'", meta.ID, meta.Version)
b.PrintDebug("Started processing plugin '%s'", meta.ID)
url := meta.URL

workDir, err := b.ioUtil.TempDir("", "theia-plugin-broker")
Expand All @@ -116,14 +116,14 @@ func (b *brokerImpl) ProcessPlugin(meta model.PluginMeta) error {
unpackedPath := filepath.Join(workDir, "plugin")

// Download an archive
b.PrintDebug("Downloading archive '%s' for plugin '%s:%s' to '%s'", url, meta.ID, meta.Version, archivePath)
b.PrintDebug("Downloading archive '%s' for plugin '%s' to '%s'", url, meta.ID, archivePath)
err = b.ioUtil.Download(url, archivePath)
if err != nil {
return err
}

// Unzip it
b.PrintDebug("Unzipping archive '%s' for plugin '%s:%s' to '%s'", url, meta.ID, meta.Version, unpackedPath)
b.PrintDebug("Unzipping archive '%s' for plugin '%s' to '%s'", url, meta.ID, unpackedPath)
err = b.ioUtil.Unzip(archivePath, unpackedPath)
if err != nil {
return err
Expand Down Expand Up @@ -171,8 +171,8 @@ func (b *brokerImpl) getPluginImage(pj *PackageJSON) (string, error) {
}

func (b *brokerImpl) injectTheiaFile(meta model.PluginMeta, archivePath string) error {
b.PrintDebug("Copying Theia plugin '%s:%s'", meta.ID, meta.Version)
pluginPath := filepath.Join("/plugins", fmt.Sprintf("%s.%s.theia", meta.ID, meta.Version))
b.PrintDebug("Copying Theia plugin '%s'", meta.ID)
pluginPath := filepath.Join("/plugins", fmt.Sprintf("%s.%s.%s.theia", meta.Publisher, meta.Name, meta.Version))
err := b.ioUtil.CopyFile(archivePath, pluginPath)
if err != nil {
return err
Expand All @@ -182,8 +182,8 @@ func (b *brokerImpl) injectTheiaFile(meta model.PluginMeta, archivePath string)

func (b *brokerImpl) injectTheiaRemotePlugin(meta model.PluginMeta, archiveFolder string, image string, pj *PackageJSON) error {
if !cfg.OnlyApplyMetadataActions {
pluginFolderPath := filepath.Join("/plugins", fmt.Sprintf("%s.%s", meta.ID, meta.Version))
b.PrintDebug("Copying Theia remote plugin '%s:%s' from '%s' to '%s'", meta.ID, meta.Version, archiveFolder, pluginFolderPath)
pluginFolderPath := filepath.Join("/plugins", fmt.Sprintf("%s.%s.%s", meta.Publisher, meta.Name, meta.Version))
b.PrintDebug("Copying Theia remote plugin '%s' from '%s' to '%s'", meta.ID, archiveFolder, pluginFolderPath)
err := b.ioUtil.CopyResource(archiveFolder, pluginFolderPath)
if err != nil {
return err
Expand Down
44 changes: 26 additions & 18 deletions brokers/theia/broker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ var (
Broker: bMock,
ioUtil: uMock,
storage: storage.New(),
rand: randMock,
rand: randMock,
}
)

Expand All @@ -46,19 +46,21 @@ func TestProcessRemotePlugin(t *testing.T) {
Broker: bMock,
ioUtil: uMock,
storage: storage.New(),
rand: randMock,
rand: randMock,
}
workDir := tests.CreateTestWorkDir()
defer tests.RemoveAll(workDir)
archivePath := filepath.Join(workDir, "pluginArchive")
unarchivedPath := filepath.Join(workDir, "plugin")
packageJSONPath := filepath.Join(unarchivedPath, "package.json")
meta := model.PluginMeta{
ID: "test-id",
Version: "test-v",
URL: "http://test.url",
ID: "test-id",
Name: "test-name",
Publisher: "test-publisher",
Version: "test-v",
URL: "http://test.url",
}
pluginPath := filepath.Join("/plugins", fmt.Sprintf("%s.%s", meta.ID, meta.Version))
pluginPath := filepath.Join("/plugins", fmt.Sprintf("%s.%s.%s", meta.Publisher, meta.Name, meta.Version))
packageJSON := PackageJSON{
PackageJSON: model.PackageJSON{
Name: "test-name",
Expand Down Expand Up @@ -101,8 +103,10 @@ func expectedPlugins(meta model.PluginMeta, image string, publisher string, pubN
prettyID := re.ReplaceAllString(publisher+"_"+pubName, `_`)
expectedPlugins := []model.ChePlugin{
{
ID: meta.ID,
Version: meta.Version,
ID: meta.ID,
Version: meta.Version,
Name: meta.Name,
Publisher: meta.Publisher,
Endpoints: []model.Endpoint{
{
Name: "randomEndpointName",
Expand Down Expand Up @@ -153,7 +157,7 @@ func TestProcessRegularPlugin(t *testing.T) {
Broker: bMock,
ioUtil: uMock,
storage: storage.New(),
rand: randMock,
rand: randMock,
}
workDir := tests.CreateTestWorkDir()
defer tests.RemoveAll(workDir)
Expand All @@ -165,7 +169,7 @@ func TestProcessRegularPlugin(t *testing.T) {
Version: "test-v",
URL: "http://test.url",
}
pluginPath := filepath.Join("/plugins", fmt.Sprintf("%s.%s.theia", meta.ID, meta.Version))
pluginPath := filepath.Join("/plugins", fmt.Sprintf("%s.%s.%s.theia", meta.Publisher, meta.Name, meta.Version))
packageJSON := PackageJSON{
PackageJSON: model.PackageJSON{
Name: "test-name",
Expand Down Expand Up @@ -320,11 +324,13 @@ func TestProcessPluginErrorIfArchiveCopyingFails(t *testing.T) {
unarchivedPath := filepath.Join(workDir, "plugin")
packageJSONPath := filepath.Join(unarchivedPath, "package.json")
meta := model.PluginMeta{
ID: "test-id",
Version: "test-v",
URL: "http://test.url",
ID: "test-id",
Version: "test-v",
Name: "test-name",
Publisher: "test-publisher",
URL: "http://test.url",
}
pluginPath := filepath.Join("/plugins", fmt.Sprintf("%s.%s.theia", meta.ID, meta.Version))
pluginPath := filepath.Join("/plugins", fmt.Sprintf("%s.%s.%s.theia", meta.Publisher, meta.Name, meta.Version))
packageJSON := PackageJSON{
PackageJSON: model.PackageJSON{
Name: "test-name",
Expand Down Expand Up @@ -359,11 +365,13 @@ func TestProcessPluginErrorIfArchiveFolderCopyingFails(t *testing.T) {
unarchivedPath := filepath.Join(workDir, "plugin")
packageJSONPath := filepath.Join(unarchivedPath, "package.json")
meta := model.PluginMeta{
ID: "test-id",
Version: "test-v",
URL: "http://test.url",
ID: "test-id",
Version: "test-v",
Name: "test-name",
Publisher: "test-publisher",
URL: "http://test.url",
}
pluginPath := filepath.Join("/plugins", fmt.Sprintf("%s.%s", meta.ID, meta.Version))
pluginPath := filepath.Join("/plugins", fmt.Sprintf("%s.%s.%s", meta.Publisher, meta.Name, meta.Version))
packageJSON := PackageJSON{
PackageJSON: model.PackageJSON{
Name: "test-name",
Expand Down
38 changes: 18 additions & 20 deletions brokers/unified/broker.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ const VscodePluginType = "vs code extension"

// RegistryURLFormat specifies the format string for registry urls
// when downloading metas
const RegistryURLFormat = "%s/%s/%s/meta.yaml"
const RegistryURLFormat = "%s/%s/meta.yaml"

// Broker is used to process Che plugins
type Broker struct {
Expand Down Expand Up @@ -73,23 +73,18 @@ func NewBroker() *Broker {
}

// DownloadMetasAndStart downloads metas from plugin registry for specified
// pluginFQNs and then calls Start for those metas
func (b *Broker) DownloadMetasAndStart(pluginFQNs []model.PluginFQN, defaultRegistry string) {
// pluginFQNs and then executes plugins metas processing and sending data to Che master
func (b *Broker) Start(pluginFQNs []model.PluginFQN, defaultRegistry string) {
pluginMetas, err := b.getPluginMetas(pluginFQNs, defaultRegistry)
if err != nil {
b.PrintFatal("Failed to download plugin metas: %s", err)
}
b.Start(pluginMetas)
}

// Start executes plugins metas processing and sending data to Che master
func (b *Broker) Start(metas []model.PluginMeta) {
defer b.CloseConsumers()
b.PubStarted()
b.PrintInfo("Unified Che Plugin Broker")
b.PrintPlan(metas)
b.PrintPlan(pluginMetas)

err := b.ProcessPlugins(metas)
err = b.ProcessPlugins(pluginMetas)
if err != nil {
b.PubFailed(err.Error())
b.PrintFatal(err.Error())
Expand Down Expand Up @@ -150,30 +145,33 @@ func (b *Broker) ProcessPlugins(metas []model.PluginMeta) error {
func (b *Broker) getPluginMetas(plugins []model.PluginFQN, defaultRegistry string) ([]model.PluginMeta, error) {
metas := make([]model.PluginMeta, 0, len(plugins))
for _, plugin := range plugins {
log.Printf("Fetching plugin meta.yaml for %s:%s", plugin.ID, plugin.Version)
log.Printf("Fetching plugin meta.yaml for %s", plugin.ID)
registry, err := getRegistryURL(plugin, defaultRegistry)
if err != nil {
return nil, err
}
pluginURL := fmt.Sprintf(RegistryURLFormat, registry, plugin.ID, plugin.Version)
pluginURL := fmt.Sprintf(RegistryURLFormat, registry, plugin.ID)
pluginRaw, err := b.utils.Fetch(pluginURL)
if err != nil {
if httpErr, ok := err.(*utils.HTTPError); ok {
return nil, fmt.Errorf(
"failed to fetch plugin meta.yaml for plugin '%s:%s' from registry '%s': %s. Response body: %s",
plugin.ID, plugin.Version, registry, httpErr, httpErr.Body)
"failed to fetch plugin meta.yaml for plugin '%s' from registry '%s': %s. Response body: %s",
plugin.ID, registry, httpErr, httpErr.Body)
} else {
return nil, fmt.Errorf(
"failed to fetch plugin meta.yaml for plugin '%s:%s' from registry '%s': %s",
plugin.ID, plugin.Version, registry, err)
"failed to fetch plugin meta.yaml for plugin '%s' from registry '%s': %s",
plugin.ID, registry, err)
}
}

var pluginMeta model.PluginMeta
if err := yaml.Unmarshal(pluginRaw, &pluginMeta); err != nil {
return nil, fmt.Errorf(
"failed to unmarshal downloaded meta.yaml for plugin '%s:%s': %s",
plugin.ID, plugin.Version, err)
"failed to unmarshal downloaded meta.yaml for plugin '%s': %s", plugin.ID, err)
}
// Ensure ID field is set since it is used all over the place in broker
if pluginMeta.ID == "" {
pluginMeta.ID = plugin.ID
}
metas = append(metas, pluginMeta)
}
Expand Down Expand Up @@ -208,9 +206,9 @@ func sortMetas(metas []model.PluginMeta) (che []model.PluginMeta, theia []model.
case TheiaPluginType:
theiaMetas = append(theiaMetas, meta)
case "":
return nil, nil, nil, fmt.Errorf("Type field is missing in meta information of plugin '%s:%s'", meta.ID, meta.Version)
return nil, nil, nil, fmt.Errorf("Type field is missing in meta information of plugin '%s'", meta.ID)
default:
return nil, nil, nil, fmt.Errorf("Type '%s' of plugin '%s:%s' is unsupported", meta.Type, meta.ID, meta.Version)
return nil, nil, nil, fmt.Errorf("Type '%s' of plugin '%s' is unsupported", meta.Type, meta.ID)
}
}

Expand Down
Loading

0 comments on commit c90e7d4

Please sign in to comment.