karaf-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "ASF GitHub Bot (JIRA)" <j...@apache.org>
Subject [jira] [Commented] (KARAF-5685) Add ProfileMBean
Date Mon, 18 Jun 2018 12:40:00 GMT

    [ https://issues.apache.org/jira/browse/KARAF-5685?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16515653#comment-16515653
] 

ASF GitHub Bot commented on KARAF-5685:
---------------------------------------

jbonofre closed pull request #530: [KARAF-5685] Add ProfileMBean
URL: https://github.com/apache/karaf/pull/530
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git a/profile/src/main/java/org/apache/karaf/profile/ProfileMBean.java b/profile/src/main/java/org/apache/karaf/profile/ProfileMBean.java
new file mode 100644
index 0000000000..89fba64719
--- /dev/null
+++ b/profile/src/main/java/org/apache/karaf/profile/ProfileMBean.java
@@ -0,0 +1,52 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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 org.apache.karaf.profile;
+
+import java.util.List;
+import java.util.Map;
+
+/**
+ * MBean to manipulate profiles.
+ */
+public interface ProfileMBean {
+
+    /**
+     * List profile IDs with parents.
+     */
+    Map<String, String> getProfiles();
+
+    /**
+     * Rename a profile.
+     */
+    void rename(String name, String newName);
+
+    /**
+     * Delete a profile.
+     */
+    void delete(String name);
+
+    /**
+     * Create a new profile.
+     */
+    void create(String name, List<String> parents);
+
+    /**
+     * Copy a profile definition on another one.
+     */
+    void copy(String source, String target);
+
+}
diff --git a/profile/src/main/java/org/apache/karaf/profile/impl/ProfileMBeanImpl.java b/profile/src/main/java/org/apache/karaf/profile/impl/ProfileMBeanImpl.java
new file mode 100644
index 0000000000..3c9a4a5014
--- /dev/null
+++ b/profile/src/main/java/org/apache/karaf/profile/impl/ProfileMBeanImpl.java
@@ -0,0 +1,87 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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 org.apache.karaf.profile.impl;
+
+import org.apache.karaf.profile.Profile;
+import org.apache.karaf.profile.ProfileBuilder;
+import org.apache.karaf.profile.ProfileMBean;
+import org.apache.karaf.profile.ProfileService;
+
+import javax.management.NotCompliantMBeanException;
+import javax.management.StandardMBean;
+import java.util.*;
+
+import static org.apache.karaf.profile.impl.Utils.join;
+
+public class ProfileMBeanImpl extends StandardMBean implements ProfileMBean {
+
+    private ProfileService profileService;
+
+    public ProfileMBeanImpl() throws NotCompliantMBeanException {
+        super(ProfileMBean.class);
+    }
+
+    @Override
+    public Map<String, String> getProfiles() {
+        List<String> ids = new ArrayList<>(profileService.getProfiles());
+        HashMap<String, String> results = new HashMap<>();
+        Collections.sort(ids);
+        for (String id : ids) {
+            Profile profile = profileService.getProfile(id);
+            if (profile != null) {
+                String parents = join(" ", profile.getParentIds());
+                results.put(id, parents);
+            }
+        }
+        return results;
+    }
+
+    @Override
+    public void rename(String name, String newName) {
+        Profile profile = ProfileBuilder.Factory.createFrom(profileService.getProfile(name))
+                .identity(newName)
+                .getProfile();
+        profileService.createProfile(profile);
+        profileService.deleteProfile(name);
+    }
+
+    @Override
+    public void delete(String name) {
+        profileService.deleteProfile(name);
+    }
+
+    @Override
+    public void create(String name, List<String> parents) {
+        Profile profile = ProfileBuilder.Factory.create(name)
+                .setParents(parents)
+                .getProfile();
+        profileService.createProfile(profile);
+    }
+
+    @Override
+    public void copy(String source, String target) {
+        Profile profile = ProfileBuilder.Factory.createFrom(profileService.getProfile(source))
+                .identity(target)
+                .getProfile();
+        profileService.createProfile(profile);
+    }
+
+    public void setProfileService(ProfileService profileService) {
+        this.profileService = profileService;
+    }
+
+}
diff --git a/profile/src/main/java/org/apache/karaf/profile/impl/osgi/Activator.java b/profile/src/main/java/org/apache/karaf/profile/impl/osgi/Activator.java
index 33a9403fa2..7ed1b2f027 100644
--- a/profile/src/main/java/org/apache/karaf/profile/impl/osgi/Activator.java
+++ b/profile/src/main/java/org/apache/karaf/profile/impl/osgi/Activator.java
@@ -19,7 +19,9 @@
 import java.nio.file.Path;
 import java.nio.file.Paths;
 
+import org.apache.karaf.profile.ProfileMBean;
 import org.apache.karaf.profile.ProfileService;
+import org.apache.karaf.profile.impl.ProfileMBeanImpl;
 import org.apache.karaf.profile.impl.ProfileServiceImpl;
 import org.apache.karaf.util.tracker.BaseActivator;
 import org.apache.karaf.util.tracker.annotation.Managed;
@@ -38,6 +40,10 @@ protected void doStart() throws Exception {
         Path root = Paths.get(getString("profilesDirectory", System.getProperty("karaf.home")
+ "/profiles"));
         ProfileServiceImpl service = new ProfileServiceImpl(root);
         register(ProfileService.class, service);
+
+        ProfileMBeanImpl profileMBean = new ProfileMBeanImpl();
+        profileMBean.setProfileService(service);
+        registerMBean(profileMBean, "type=profile");
     }
 
 }


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


> Add ProfileMBean
> ----------------
>
>                 Key: KARAF-5685
>                 URL: https://issues.apache.org/jira/browse/KARAF-5685
>             Project: Karaf
>          Issue Type: Improvement
>          Components: karaf-management
>            Reporter: Jean-Baptiste Onofré
>            Assignee: Jean-Baptiste Onofré
>            Priority: Major
>             Fix For: 4.2.1
>
>
> As we have the {{profile:*}} commands, it would be great to have a {{ProfileMBean}} exposing
the same operations as the shell commands.



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

Mime
View raw message