From b38d9b82b6de3f240f96281f61854dd114cdd261 Mon Sep 17 00:00:00 2001 From: Kelven Yang Date: Tue, 13 Nov 2012 17:59:11 -0800 Subject: [PATCH] CloudStack messaging refactoring skeleton --- framework/events/.project | 17 ----- .../messaging/ComponentEndpoint.java | 75 +++++++++++++++++++ .../framework/messaging/RpcCall.java | 27 +++++++ .../framework/messaging/RpcCallHandler.java | 30 ++++++++ .../framework/messaging/RpcEndpoint.java | 26 +++++++ .../framework/messaging/RpcProvider.java | 24 ++++++ .../messaging/TransportAddressFactory.java | 23 ++++++ .../messaging/TransportEndpoint.java | 29 +++++++ .../messaging/TransportMultiplexier.java | 24 ++++++ .../messaging/TransportProvider.java | 24 ++++++ .../client/ClientTransportEndpoint.java | 47 ++++++++++++ .../client/ClientTransportProvider.java | 35 +++++++++ .../server/ServerTransportProvider.java | 37 +++++++++ framework/jobs/.project | 23 ------ .../cloud/servlet/CloudStartupServlet.java | 54 +++++++++++++ 15 files changed, 455 insertions(+), 40 deletions(-) delete mode 100755 framework/events/.project create mode 100644 framework/ipc/src/org/apache/cloudstack/framework/messaging/ComponentEndpoint.java create mode 100644 framework/ipc/src/org/apache/cloudstack/framework/messaging/RpcCall.java create mode 100644 framework/ipc/src/org/apache/cloudstack/framework/messaging/RpcCallHandler.java create mode 100644 framework/ipc/src/org/apache/cloudstack/framework/messaging/RpcEndpoint.java create mode 100644 framework/ipc/src/org/apache/cloudstack/framework/messaging/RpcProvider.java create mode 100644 framework/ipc/src/org/apache/cloudstack/framework/messaging/TransportAddressFactory.java create mode 100644 framework/ipc/src/org/apache/cloudstack/framework/messaging/TransportEndpoint.java create mode 100644 framework/ipc/src/org/apache/cloudstack/framework/messaging/TransportMultiplexier.java create mode 100644 framework/ipc/src/org/apache/cloudstack/framework/messaging/TransportProvider.java create mode 100644 framework/ipc/src/org/apache/cloudstack/framework/messaging/client/ClientTransportEndpoint.java create mode 100644 framework/ipc/src/org/apache/cloudstack/framework/messaging/client/ClientTransportProvider.java create mode 100644 framework/ipc/src/org/apache/cloudstack/framework/messaging/server/ServerTransportProvider.java delete mode 100755 framework/jobs/.project diff --git a/framework/events/.project b/framework/events/.project deleted file mode 100755 index 677cea5251f..00000000000 --- a/framework/events/.project +++ /dev/null @@ -1,17 +0,0 @@ - - - framework-events - - - - - - org.eclipse.jdt.core.javabuilder - - - - - - org.eclipse.jdt.core.javanature - - diff --git a/framework/ipc/src/org/apache/cloudstack/framework/messaging/ComponentEndpoint.java b/framework/ipc/src/org/apache/cloudstack/framework/messaging/ComponentEndpoint.java new file mode 100644 index 00000000000..0c55b301277 --- /dev/null +++ b/framework/ipc/src/org/apache/cloudstack/framework/messaging/ComponentEndpoint.java @@ -0,0 +1,75 @@ +/* + * 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.cloudstack.framework.messaging; + +public class ComponentEndpoint implements RpcEndpoint, TransportMultiplexier { + + private TransportEndpoint transportEndpoint; + private RpcProvider rpcProvider; + + public ComponentEndpoint() { + } + + public TransportEndpoint getTransportEndpoint() { + return transportEndpoint; + } + + public void setTransportEndpoint(TransportEndpoint transportEndpoint) { + this.transportEndpoint = transportEndpoint; + } + + public RpcProvider getRpcProvider() { + return rpcProvider; + } + + public void setRpcProvider(RpcProvider rpcProvider) { + this.rpcProvider = rpcProvider; + } + + public void initialize(String[] multiplexiers) { + if(multiplexiers != null) { + for(String name : multiplexiers) + transportEndpoint.registerMultiplexier(name, this); + } + + rpcProvider.registerRpcEndpoint(this); + } + + @Override + public void onTransportMessage(String senderEndpointAddress, + String targetEndpointAddress, String multiplexer, String message) { + } + + @Override + public String call(String targetAddress, String rpcMessage) { + // TODO Auto-generated method stub + return null; + } + + @Override + public void asyncCall(String targetAddress, String rpcMessage) { + // TODO Auto-generated method stub + } + + @Override + public void onCall(RpcCall call) { + // TODO Auto-generated method stub + + } +} diff --git a/framework/ipc/src/org/apache/cloudstack/framework/messaging/RpcCall.java b/framework/ipc/src/org/apache/cloudstack/framework/messaging/RpcCall.java new file mode 100644 index 00000000000..be16bdd3e91 --- /dev/null +++ b/framework/ipc/src/org/apache/cloudstack/framework/messaging/RpcCall.java @@ -0,0 +1,27 @@ +/* + * 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.cloudstack.framework.messaging; + +public interface RpcCall { + String getCommand(); + String getContent(); + String getRequestTag(); + + void completeCall(String rpcMessage); +} diff --git a/framework/ipc/src/org/apache/cloudstack/framework/messaging/RpcCallHandler.java b/framework/ipc/src/org/apache/cloudstack/framework/messaging/RpcCallHandler.java new file mode 100644 index 00000000000..2d940645114 --- /dev/null +++ b/framework/ipc/src/org/apache/cloudstack/framework/messaging/RpcCallHandler.java @@ -0,0 +1,30 @@ +/* + * 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.cloudstack.framework.messaging; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +@Retention(RetentionPolicy.RUNTIME) +@Target(ElementType.METHOD) +public @interface RpcCallHandler { + String command(); +} diff --git a/framework/ipc/src/org/apache/cloudstack/framework/messaging/RpcEndpoint.java b/framework/ipc/src/org/apache/cloudstack/framework/messaging/RpcEndpoint.java new file mode 100644 index 00000000000..62dc97354fa --- /dev/null +++ b/framework/ipc/src/org/apache/cloudstack/framework/messaging/RpcEndpoint.java @@ -0,0 +1,26 @@ +/* + * 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.cloudstack.framework.messaging; + +public interface RpcEndpoint { + public String call(String targetAddress, String rpcMessage); + public void asyncCall(String targetAddress, String rpcMessage); + + void onCall(RpcCall call); +} diff --git a/framework/ipc/src/org/apache/cloudstack/framework/messaging/RpcProvider.java b/framework/ipc/src/org/apache/cloudstack/framework/messaging/RpcProvider.java new file mode 100644 index 00000000000..cbdd4a7342d --- /dev/null +++ b/framework/ipc/src/org/apache/cloudstack/framework/messaging/RpcProvider.java @@ -0,0 +1,24 @@ +/* + * 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.cloudstack.framework.messaging; + +public interface RpcProvider extends TransportMultiplexier { + public void registerRpcEndpoint(RpcEndpoint rpcEndpoint); + public void unregisteRpcEndpoint(RpcEndpoint rpcEndpoint); +} diff --git a/framework/ipc/src/org/apache/cloudstack/framework/messaging/TransportAddressFactory.java b/framework/ipc/src/org/apache/cloudstack/framework/messaging/TransportAddressFactory.java new file mode 100644 index 00000000000..d7f3e9de5f2 --- /dev/null +++ b/framework/ipc/src/org/apache/cloudstack/framework/messaging/TransportAddressFactory.java @@ -0,0 +1,23 @@ +/* + * 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.cloudstack.framework.messaging; + +public interface TransportAddressFactory { + String createServiceAddress(String serviceProvider); +} diff --git a/framework/ipc/src/org/apache/cloudstack/framework/messaging/TransportEndpoint.java b/framework/ipc/src/org/apache/cloudstack/framework/messaging/TransportEndpoint.java new file mode 100644 index 00000000000..68982e2bdea --- /dev/null +++ b/framework/ipc/src/org/apache/cloudstack/framework/messaging/TransportEndpoint.java @@ -0,0 +1,29 @@ +/* + * 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.cloudstack.framework.messaging; + +public interface TransportEndpoint { + void onAttachConfirm(String endpointAddress); + + void registerMultiplexier(String name, TransportMultiplexier multiplexier); + void unregisterMultiplexier(String name); + + void sendMessage(TransportEndpoint sender, String targetEndpointAddress, + String multiplexier, String message); +} diff --git a/framework/ipc/src/org/apache/cloudstack/framework/messaging/TransportMultiplexier.java b/framework/ipc/src/org/apache/cloudstack/framework/messaging/TransportMultiplexier.java new file mode 100644 index 00000000000..2e8e570b8d3 --- /dev/null +++ b/framework/ipc/src/org/apache/cloudstack/framework/messaging/TransportMultiplexier.java @@ -0,0 +1,24 @@ +/* + * 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.cloudstack.framework.messaging; + +public interface TransportMultiplexier { + public void onTransportMessage(String senderEndpointAddress, String targetEndpointAddress, + String multiplexer, String message); +} diff --git a/framework/ipc/src/org/apache/cloudstack/framework/messaging/TransportProvider.java b/framework/ipc/src/org/apache/cloudstack/framework/messaging/TransportProvider.java new file mode 100644 index 00000000000..6773e8d0ba6 --- /dev/null +++ b/framework/ipc/src/org/apache/cloudstack/framework/messaging/TransportProvider.java @@ -0,0 +1,24 @@ +/* + * 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.cloudstack.framework.messaging; + +public interface TransportProvider { + void attach(TransportEndpoint endpoint, String predefinedAddress); + void detach(TransportEndpoint endpoint); +} diff --git a/framework/ipc/src/org/apache/cloudstack/framework/messaging/client/ClientTransportEndpoint.java b/framework/ipc/src/org/apache/cloudstack/framework/messaging/client/ClientTransportEndpoint.java new file mode 100644 index 00000000000..8ee4b8ff3d5 --- /dev/null +++ b/framework/ipc/src/org/apache/cloudstack/framework/messaging/client/ClientTransportEndpoint.java @@ -0,0 +1,47 @@ +/* + * 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.cloudstack.framework.messaging.client; + +import org.apache.cloudstack.framework.messaging.TransportEndpoint; +import org.apache.cloudstack.framework.messaging.TransportMultiplexier; + +public class ClientTransportEndpoint implements TransportEndpoint { + + @Override + public void onAttachConfirm(String endpointAddress) { + // TODO Auto-generated method stub + } + + @Override + public void registerMultiplexier(String name, + TransportMultiplexier multiplexier) { + // TODO Auto-generated method stub + } + + @Override + public void unregisterMultiplexier(String name) { + // TODO Auto-generated method stub + } + + @Override + public void sendMessage(TransportEndpoint sender, + String targetEndpointAddress, String multiplexier, String message) { + // TODO Auto-generated method stub + } +} diff --git a/framework/ipc/src/org/apache/cloudstack/framework/messaging/client/ClientTransportProvider.java b/framework/ipc/src/org/apache/cloudstack/framework/messaging/client/ClientTransportProvider.java new file mode 100644 index 00000000000..665d207a762 --- /dev/null +++ b/framework/ipc/src/org/apache/cloudstack/framework/messaging/client/ClientTransportProvider.java @@ -0,0 +1,35 @@ +/* + * 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.cloudstack.framework.messaging.client; + +import org.apache.cloudstack.framework.messaging.TransportEndpoint; +import org.apache.cloudstack.framework.messaging.TransportProvider; + +public class ClientTransportProvider implements TransportProvider { + + @Override + public void attach(TransportEndpoint endpoint, String predefinedAddress) { + // TODO Auto-generated method stub + } + + @Override + public void detach(TransportEndpoint endpoint) { + // TODO Auto-generated method stub + } +} diff --git a/framework/ipc/src/org/apache/cloudstack/framework/messaging/server/ServerTransportProvider.java b/framework/ipc/src/org/apache/cloudstack/framework/messaging/server/ServerTransportProvider.java new file mode 100644 index 00000000000..1f7c12bfc8d --- /dev/null +++ b/framework/ipc/src/org/apache/cloudstack/framework/messaging/server/ServerTransportProvider.java @@ -0,0 +1,37 @@ +/* + * 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.cloudstack.framework.messaging.server; + +import org.apache.cloudstack.framework.messaging.TransportEndpoint; +import org.apache.cloudstack.framework.messaging.TransportProvider; + +public class ServerTransportProvider implements TransportProvider { + + @Override + public void attach(TransportEndpoint endpoint, String predefinedAddress) { + // TODO Auto-generated method stub + + } + + @Override + public void detach(TransportEndpoint endpoint) { + // TODO Auto-generated method stub + + } +} diff --git a/framework/jobs/.project b/framework/jobs/.project deleted file mode 100755 index ddf0af05b47..00000000000 --- a/framework/jobs/.project +++ /dev/null @@ -1,23 +0,0 @@ - - - cloud-framework-jobs - - - - - - org.eclipse.jdt.core.javabuilder - - - - - org.eclipse.m2e.core.maven2Builder - - - - - - org.eclipse.m2e.core.maven2Nature - org.eclipse.jdt.core.javanature - - diff --git a/server/src/com/cloud/servlet/CloudStartupServlet.java b/server/src/com/cloud/servlet/CloudStartupServlet.java index e38b9235be8..93b6e000c1e 100755 --- a/server/src/com/cloud/servlet/CloudStartupServlet.java +++ b/server/src/com/cloud/servlet/CloudStartupServlet.java @@ -16,6 +16,9 @@ // under the License. package com.cloud.servlet; +import java.util.Map; +import java.util.Set; + import javax.servlet.ServletContextEvent; import javax.servlet.ServletContextListener; import javax.servlet.ServletException; @@ -28,7 +31,12 @@ import com.cloud.exception.InvalidParameterValueException; import com.cloud.server.ConfigurationServer; import com.cloud.server.ManagementServer; import com.cloud.utils.SerialVersionUID; +import com.cloud.utils.component.ComponentContext; import com.cloud.utils.component.ComponentLocator; +import com.cloud.utils.component.SystemIntegrityChecker; +import com.cloud.utils.component.LegacyComponentLocator.ComponentInfo; +import com.cloud.utils.db.GenericDao; +import com.cloud.utils.db.GenericDaoBase; public class CloudStartupServlet extends HttpServlet implements ServletContextListener { public static final Logger s_logger = Logger.getLogger(CloudStartupServlet.class.getName()); @@ -71,4 +79,50 @@ public class CloudStartupServlet extends HttpServlet implements ServletContextLi @Override public void contextDestroyed(ServletContextEvent sce) { } + + // + // following should be moved to CloudStackServer component later to encapsulate business logic in one place + // + private void initCloudStackComponents() { + runCheckers(); + startDaos(); // daos should not be using managers and adapters. + +/* + configureManagers(); + configureAdapters(); + startManagers(); + startAdapters(); +*/ + } + + private void runCheckers() { + Map checkers = ComponentContext.getApplicationContext().getBeansOfType( + SystemIntegrityChecker.class); + + for(SystemIntegrityChecker checker : checkers.values()) { + try { + checker.check(); + } catch (Exception e) { + s_logger.error("Problems with running checker:" + checker.getClass().getName(), e); + System.exit(1); + } + } + } + + private void startDaos() { + @SuppressWarnings("rawtypes") + Map daos = ComponentContext.getApplicationContext().getBeansOfType( + GenericDaoBase.class); + + for(GenericDaoBase dao : daos.values()) { + try { + + // dao.configure(dao.getClass().getSimpleName(), params); + } catch (Exception e) { + s_logger.error("Problems with running checker:" + dao.getClass().getName(), e); + System.exit(1); + } + } + } + }