CloudStack messaging refactoring skeleton

This commit is contained in:
Kelven Yang 2012-11-13 17:59:11 -08:00
parent a06eb4557e
commit b38d9b82b6
15 changed files with 455 additions and 40 deletions

View File

@ -1,17 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>framework-events</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
</projectDescription>

View File

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

View File

@ -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);
}

View File

@ -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();
}

View File

@ -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);
}

View File

@ -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);
}

View File

@ -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);
}

View File

@ -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);
}

View File

@ -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);
}

View File

@ -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);
}

View File

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

View File

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

View File

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

View File

@ -1,23 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>cloud-framework-jobs</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.m2e.core.maven2Builder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.m2e.core.maven2Nature</nature>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
</projectDescription>

View File

@ -16,6 +16,9 @@
// under the License. // under the License.
package com.cloud.servlet; package com.cloud.servlet;
import java.util.Map;
import java.util.Set;
import javax.servlet.ServletContextEvent; import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener; import javax.servlet.ServletContextListener;
import javax.servlet.ServletException; import javax.servlet.ServletException;
@ -28,7 +31,12 @@ import com.cloud.exception.InvalidParameterValueException;
import com.cloud.server.ConfigurationServer; import com.cloud.server.ConfigurationServer;
import com.cloud.server.ManagementServer; import com.cloud.server.ManagementServer;
import com.cloud.utils.SerialVersionUID; import com.cloud.utils.SerialVersionUID;
import com.cloud.utils.component.ComponentContext;
import com.cloud.utils.component.ComponentLocator; 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 class CloudStartupServlet extends HttpServlet implements ServletContextListener {
public static final Logger s_logger = Logger.getLogger(CloudStartupServlet.class.getName()); public static final Logger s_logger = Logger.getLogger(CloudStartupServlet.class.getName());
@ -71,4 +79,50 @@ public class CloudStartupServlet extends HttpServlet implements ServletContextLi
@Override @Override
public void contextDestroyed(ServletContextEvent sce) { 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<String, SystemIntegrityChecker> 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<String, GenericDaoBase> 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);
}
}
}
} }