forked from spinnaker/gate
-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
OP-20633, OP-21175: feature implementing the user logged in events AP…
…I's and Publish user details as events to rabbitmq. (#428)
- Loading branch information
1 parent
f8238de
commit e390e6d
Showing
14 changed files
with
333 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 51 additions & 0 deletions
51
gate-web/src/main/java/com/netflix/spinnaker/gate/config/CamelConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
/* | ||
* Copyright 2021 OpsMx, Inc. | ||
* | ||
* 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 com.netflix.spinnaker.gate.config; | ||
|
||
import java.util.concurrent.TimeUnit; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.apache.camel.CamelContext; | ||
import org.apache.camel.ProducerTemplate; | ||
import org.apache.camel.impl.DefaultCamelContext; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.boot.autoconfigure.condition.ConditionalOnExpression; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
|
||
@Slf4j | ||
@Configuration | ||
@ConditionalOnExpression("${message-broker.enabled:true}") | ||
public class CamelConfig { | ||
|
||
@Autowired private UserActivityRouteBuilder userActivityRouteBuilder; | ||
|
||
@Bean | ||
public CamelContext camelContext() throws Exception { | ||
CamelContext camelContext = new DefaultCamelContext(); | ||
camelContext.addRoutes(userActivityRouteBuilder); | ||
camelContext.getShutdownStrategy().setShutdownNowOnTimeout(true); | ||
camelContext.getShutdownStrategy().setTimeout(5); | ||
camelContext.getShutdownStrategy().setTimeUnit(TimeUnit.SECONDS); | ||
camelContext.start(); | ||
return camelContext; | ||
} | ||
|
||
@Bean | ||
public ProducerTemplate producerTemplate(CamelContext camelContext) { | ||
return camelContext.createProducerTemplate(); | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
gate-web/src/main/java/com/netflix/spinnaker/gate/config/CamelRouteConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
/* | ||
* Copyright 2021 OpsMx, Inc. | ||
* | ||
* 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 com.netflix.spinnaker.gate.config; | ||
|
||
public interface CamelRouteConfig { | ||
String getUserActivityQueueEndPoint(); | ||
} |
49 changes: 49 additions & 0 deletions
49
gate-web/src/main/java/com/netflix/spinnaker/gate/config/MessageBrokerProperties.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
/* | ||
* Copyright 2021 OpsMx, Inc. | ||
* | ||
* 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 com.netflix.spinnaker.gate.config; | ||
|
||
import lombok.Data; | ||
import org.springframework.boot.autoconfigure.condition.ConditionalOnExpression; | ||
import org.springframework.boot.context.properties.ConfigurationProperties; | ||
import org.springframework.boot.context.properties.EnableConfigurationProperties; | ||
import org.springframework.context.annotation.Configuration; | ||
|
||
@Data | ||
@Configuration | ||
@ConfigurationProperties(prefix = "message-broker") | ||
@ConditionalOnExpression("${message-broker.enabled:true}") | ||
@EnableConfigurationProperties({ | ||
MessageBrokerProperties.class, | ||
MessageBrokerProperties.Endpoint.class | ||
}) | ||
public class MessageBrokerProperties { | ||
|
||
private boolean enabled; | ||
private String username; | ||
private String password; | ||
private String host; | ||
private String port; | ||
private Endpoint endpoint; | ||
|
||
@Data | ||
@Configuration | ||
@ConditionalOnExpression("${message-broker.enabled:true}") | ||
@ConfigurationProperties(prefix = "message-broker.endpoint") | ||
public static class Endpoint { | ||
private String name; | ||
} | ||
} |
51 changes: 51 additions & 0 deletions
51
gate-web/src/main/java/com/netflix/spinnaker/gate/config/RabbitMQConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
/* | ||
* Copyright 2021 OpsMx, Inc. | ||
* | ||
* 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 com.netflix.spinnaker.gate.config; | ||
|
||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.boot.autoconfigure.condition.ConditionalOnExpression; | ||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; | ||
import org.springframework.context.annotation.Configuration; | ||
|
||
@Configuration | ||
@ConditionalOnExpression("${message-broker.enabled:true}") | ||
@ConditionalOnProperty(value = "message-broker.endpoint.name", havingValue = "rabbitmq") | ||
public class RabbitMQConfig implements CamelRouteConfig { | ||
|
||
@Autowired private MessageBrokerProperties messageBrokerProperties; | ||
private static final String isdExchange = "isd.userLoginDetails"; | ||
private String directUserActivity = "userLoginDetails"; | ||
|
||
@Override | ||
public String getUserActivityQueueEndPoint() { | ||
return messageBrokerProperties.getEndpoint().getName() | ||
+ ":" | ||
+ isdExchange | ||
+ "?queue=" | ||
+ directUserActivity | ||
+ "&autoDelete=false&routingKey=" | ||
+ directUserActivity | ||
+ "&declare=true&durable=true&exchangeType=direct&hostname=" | ||
+ messageBrokerProperties.getHost() | ||
+ "&portNumber=" | ||
+ messageBrokerProperties.getPort() | ||
+ "&username=" | ||
+ messageBrokerProperties.getUsername() | ||
+ "&password=" | ||
+ messageBrokerProperties.getPassword(); | ||
} | ||
} |
41 changes: 41 additions & 0 deletions
41
gate-web/src/main/java/com/netflix/spinnaker/gate/config/UserActivityRouteBuilder.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
/* | ||
* Copyright 2021 OpsMx, Inc. | ||
* | ||
* 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 com.netflix.spinnaker.gate.config; | ||
|
||
import static com.opsmx.spinnaker.gate.constant.CamelEndpointConstant.directUserActivity; | ||
|
||
import org.apache.camel.builder.RouteBuilder; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.boot.autoconfigure.condition.ConditionalOnExpression; | ||
import org.springframework.context.annotation.Configuration; | ||
|
||
@Configuration | ||
@ConditionalOnExpression("${message-broker.enabled:true}") | ||
public class UserActivityRouteBuilder extends RouteBuilder { | ||
|
||
private final String userActivity = "userActivity"; | ||
@Autowired private CamelRouteConfig camelRouteConfig; | ||
|
||
@Override | ||
public void configure() throws Exception { | ||
|
||
from(directUserActivity) | ||
.id(userActivity) | ||
.to(camelRouteConfig.getUserActivityQueueEndPoint()) | ||
.end(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.