You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@camel.apache.org by GitBox <gi...@apache.org> on 2019/01/24 16:31:33 UTC

[GitHub] astefanutti commented on a change in pull request #375: Jolokia trait initial implementation

astefanutti commented on a change in pull request #375: Jolokia trait initial implementation
URL: https://github.com/apache/camel-k/pull/375#discussion_r250681286
 
 

 ##########
 File path: pkg/trait/jolokia.go
 ##########
 @@ -0,0 +1,91 @@
+/*
+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 trait
+
+import (
+	"strconv"
+
+	"github.com/apache/camel-k/pkg/apis/camel/v1alpha1"
+	"github.com/apache/camel-k/pkg/util/envvar"
+	"github.com/sirupsen/logrus"
+)
+
+type jolokiaTrait struct {
+	BaseTrait `property:",squash"`
+
+	OpenShiftSSLAuth *bool   `property:"openshiftSSLAuth"`
+	Options          *string `property:"options"`
+	Port             int     `property:"port"`
+	RandomPassword   *bool   `property:"randomPassword"`
+}
+
+// The Jolokia trait must be executed prior to the deployment trait
+// as it mutates environment variables
+func newJolokiaTrait() *jolokiaTrait {
+	return &jolokiaTrait{
+		BaseTrait: BaseTrait{
+			id: ID("jolokia"),
+		},
+		Port: 8778,
+	}
+}
+
+func (t *jolokiaTrait) Configure(e *Environment) (bool, error) {
+	enabled := false
+
+	if e.IntegrationInPhase(v1alpha1.IntegrationPhaseDeploying) && t.Enabled != nil && *t.Enabled {
+		enabled = true
+	}
+
+	// Deactivate the Jolokia Java agent accordingly
+	// Note: the AB_JOLOKIA_OFF environment variable acts as an option flag
+	if !enabled {
+		envvar.SetVal(&e.EnvVars, "AB_JOLOKIA_OFF", "true")
 
 Review comment:
   I wondered that as well :)
   
   An alternative approach would be to deactivate Jolokia in the deployment trait unless the Jolokia trait is enabled. That would have to be done by checking if the `AB_JOLOKIA_OFF` environment variable has been set already. I initially found that this alternative scatters the trait logic and is a bit brittle compare to _hi-jacking_ the `configure` method.
   
   WDYT?

----------------------------------------------------------------
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


With regards,
Apache Git Services