diff --git a/agent/.settings/org.eclipse.core.resources.prefs b/agent/.settings/org.eclipse.core.resources.prefs index c2e657a753b..99f26c0203a 100644 --- a/agent/.settings/org.eclipse.core.resources.prefs +++ b/agent/.settings/org.eclipse.core.resources.prefs @@ -1,3 +1,2 @@ -#Mon Aug 27 14:48:15 PDT 2012 eclipse.preferences.version=1 encoding/=UTF-8 diff --git a/awsapi/.settings/org.eclipse.core.resources.prefs b/awsapi/.settings/org.eclipse.core.resources.prefs index ab6a17adcf2..99f26c0203a 100644 --- a/awsapi/.settings/org.eclipse.core.resources.prefs +++ b/awsapi/.settings/org.eclipse.core.resources.prefs @@ -1,3 +1,2 @@ -#Mon Aug 27 14:48:16 PDT 2012 eclipse.preferences.version=1 encoding/=UTF-8 diff --git a/console-proxy/.settings/org.eclipse.core.resources.prefs b/console-proxy/.settings/org.eclipse.core.resources.prefs index c2e657a753b..99f26c0203a 100644 --- a/console-proxy/.settings/org.eclipse.core.resources.prefs +++ b/console-proxy/.settings/org.eclipse.core.resources.prefs @@ -1,3 +1,2 @@ -#Mon Aug 27 14:48:15 PDT 2012 eclipse.preferences.version=1 encoding/=UTF-8 diff --git a/core/.settings/org.eclipse.core.resources.prefs b/core/.settings/org.eclipse.core.resources.prefs index c2e657a753b..99f26c0203a 100644 --- a/core/.settings/org.eclipse.core.resources.prefs +++ b/core/.settings/org.eclipse.core.resources.prefs @@ -1,3 +1,2 @@ -#Mon Aug 27 14:48:15 PDT 2012 eclipse.preferences.version=1 encoding/=UTF-8 diff --git a/platform/api/src/org/apache/cloudstack/platform/service/api/OrchestrationService.java b/platform/api/src/org/apache/cloudstack/platform/service/api/OrchestrationService.java index 1eb0474ea6f..09edd9f2b83 100755 --- a/platform/api/src/org/apache/cloudstack/platform/service/api/OrchestrationService.java +++ b/platform/api/src/org/apache/cloudstack/platform/service/api/OrchestrationService.java @@ -28,7 +28,7 @@ import com.cloud.vm.VirtualMachine; public interface OrchestrationService { /** - * Reserves a new virtual machine + * creates a new virtual machine * * @param uuid externally unique name to reference the virtual machine * @param template reference to the template @@ -42,7 +42,7 @@ public interface OrchestrationService { * @param details extra details to store for the VM * @return VirtualMachine */ - VirtualMachine create(String uuid, + VirtualMachine create(String name, String template, String hostName, int cpu, @@ -84,7 +84,6 @@ public interface OrchestrationService { * @return job Id * @throws CloudRuntimeException if error */ - @Job(callback=) String deploy(String reservationId); /** diff --git a/platform/api/src/org/apache/cloudstack/platform/subsystem/api/network/NetworkSubsystem.java b/platform/api/src/org/apache/cloudstack/platform/subsystem/api/network/NetworkSubsystem.java index 7e28ed3b848..6a373821c23 100755 --- a/platform/api/src/org/apache/cloudstack/platform/subsystem/api/network/NetworkSubsystem.java +++ b/platform/api/src/org/apache/cloudstack/platform/subsystem/api/network/NetworkSubsystem.java @@ -19,7 +19,7 @@ package org.apache.cloudstack.platform.subsystem.api.network; public interface NetworkSubsystem { - String createNetwork(); + String create(); String start(String network, String reservationId); diff --git a/platform/api/src/org/apache/cloudstack/platform/subsystem/api/storage/DataMigrationSubSystem.java b/platform/api/src/org/apache/cloudstack/platform/subsystem/api/storage/DataMigrationSubSystem.java index 30185b7835f..edb15a64ed2 100755 --- a/platform/api/src/org/apache/cloudstack/platform/subsystem/api/storage/DataMigrationSubSystem.java +++ b/platform/api/src/org/apache/cloudstack/platform/subsystem/api/storage/DataMigrationSubSystem.java @@ -18,6 +18,12 @@ */ package org.apache.cloudstack.platform.subsystem.api.storage; +import java.net.URI; + +import com.cloud.org.Grouping; + public interface DataMigrationSubSystem { - void migrate(String volume, String storagePool, String reservationId); + + Class getScopeCoverage(); + void migrate(URI source, URI dest, String reservationId); } diff --git a/platform/api/src/org/apache/cloudstack/platform/subsystem/api/storage/StorageSubSystem.java b/platform/api/src/org/apache/cloudstack/platform/subsystem/api/storage/StorageSubSystem.java index e12ff797ad4..bef7586d9c2 100755 --- a/platform/api/src/org/apache/cloudstack/platform/subsystem/api/storage/StorageSubSystem.java +++ b/platform/api/src/org/apache/cloudstack/platform/subsystem/api/storage/StorageSubSystem.java @@ -8,6 +8,8 @@ public interface StorageSubSystem { String getType(); Class getScope(); + create(); + URI grantAccess(String vol, String reservationId); URI RemoveAccess(String vol, String reservationId); } diff --git a/platform/compute/src/org/apache/cloudstack/compute/ComputeOrchestrator.java b/platform/compute/src/org/apache/cloudstack/compute/ComputeOrchestrator.java index 21813ab043b..1018f96858f 100755 --- a/platform/compute/src/org/apache/cloudstack/compute/ComputeOrchestrator.java +++ b/platform/compute/src/org/apache/cloudstack/compute/ComputeOrchestrator.java @@ -27,7 +27,6 @@ public interface ComputeOrchestrator { * @param vm vm * @param reservationId */ - @Ipc(topic="cs.compute.start") void start(@IpcParam String vm, @IpcParam String reservationId); @Ipc(topic="cs.compute.cancel") diff --git a/server/.settings/org.eclipse.core.resources.prefs b/server/.settings/org.eclipse.core.resources.prefs index c2e657a753b..99f26c0203a 100644 --- a/server/.settings/org.eclipse.core.resources.prefs +++ b/server/.settings/org.eclipse.core.resources.prefs @@ -1,3 +1,2 @@ -#Mon Aug 27 14:48:15 PDT 2012 eclipse.preferences.version=1 encoding/=UTF-8 diff --git a/setup/db/create-schema.sql b/setup/db/create-schema.sql index fa933e3be70..54b096751d8 100755 --- a/setup/db/create-schema.sql +++ b/setup/db/create-schema.sql @@ -1011,6 +1011,7 @@ CREATE TABLE `cloud`.`vm_instance` ( `uuid` varchar(40), `instance_name` varchar(255) NOT NULL COMMENT 'name of the vm instance running on the hosts', `state` varchar(32) NOT NULL, + `desired_state` varchar(32) NULL, `vm_template_id` bigint unsigned, `guest_os_id` bigint unsigned NOT NULL, `private_mac_address` varchar(17), diff --git a/usage/.settings/org.eclipse.core.resources.prefs b/usage/.settings/org.eclipse.core.resources.prefs index c2e657a753b..99f26c0203a 100644 --- a/usage/.settings/org.eclipse.core.resources.prefs +++ b/usage/.settings/org.eclipse.core.resources.prefs @@ -1,3 +1,2 @@ -#Mon Aug 27 14:48:15 PDT 2012 eclipse.preferences.version=1 encoding/=UTF-8 diff --git a/utils/.settings/org.eclipse.core.resources.prefs b/utils/.settings/org.eclipse.core.resources.prefs index ab6a17adcf2..99f26c0203a 100644 --- a/utils/.settings/org.eclipse.core.resources.prefs +++ b/utils/.settings/org.eclipse.core.resources.prefs @@ -1,3 +1,2 @@ -#Mon Aug 27 14:48:16 PDT 2012 eclipse.preferences.version=1 encoding/=UTF-8 diff --git a/utils/src/com/cloud/utils/db/Condition.java b/utils/src/com/cloud/utils/db/Condition.java deleted file mode 100644 index 55b19d81e5e..00000000000 --- a/utils/src/com/cloud/utils/db/Condition.java +++ /dev/null @@ -1,100 +0,0 @@ -// 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 -// 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.cloud.utils.db; - -import java.util.HashMap; - -import com.cloud.utils.db.SearchCriteria.Op; - -public class Condition { - Where _where; - Attribute _attr; - String _as; - SearchCriteria.Op _op; - String _paramName; - - protected Condition(Where where, Attribute attr, String as) { - assert (where != null) : "What am I going to return to the user when Where is null?"; - assert (attr != null) : "What's the point of giving me a null attribute?"; - _where = where; - _attr = attr; - _as = as; - } - - protected NextWhere set(Op op, String paramName) { - _op = op; - _paramName = paramName; - Where where = _where; - _where = null; - return where; - } - - public NextWhere eq(String paramName) { - return set(Op.EQ, paramName); - } - - public NextWhere lt(String paramName) { - return set(Op.LT, paramName); - } - - public NextWhere lteq(String paramName) { - return set(Op.LTEQ, paramName); - } - - public NextWhere gt(String paramName) { - return set(Op.GT, paramName); - } - - public NextWhere isNull() { - return set(Op.NULL, null); - } - - public NextWhere isNotNull() { - return set(Op.NNULL, null); - } - - public NextWhere in(String paramName) { - _op = Op.IN; - _paramName = paramName; - return _where; - } - - protected String getParamName() { - assert (_paramName instanceof String) : "Well, how can we get back a parameter name if it was not assigned one?"; - return _paramName; - } - - @Override - public boolean equals(Object obj) { - return _paramName.equals(obj); - } - - @Override - public int hashCode() { - return _paramName.hashCode(); - } - - public void toSql(StringBuilder builder, HashMap values) { - if (_as != null) { - builder.append(_as); - } else { - builder.append(_attr.table); - } - builder.append(".").append(_attr.columnName); - } - -} diff --git a/utils/src/com/cloud/utils/db/FirstWhere.java b/utils/src/com/cloud/utils/db/FirstWhere.java deleted file mode 100644 index 46551e909b0..00000000000 --- a/utils/src/com/cloud/utils/db/FirstWhere.java +++ /dev/null @@ -1,29 +0,0 @@ -// 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 -// 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.cloud.utils.db; - -public interface FirstWhere { - Condition field(Object field); - - Condition field(Object field, String as); - - NextWhere text(String text, String... paramNames); - - FirstWhere op(); - - void done(); -} diff --git a/utils/src/com/cloud/utils/db/JoinQueryBuilder.java b/utils/src/com/cloud/utils/db/JoinQueryBuilder.java deleted file mode 100644 index 090a1d13899..00000000000 --- a/utils/src/com/cloud/utils/db/JoinQueryBuilder.java +++ /dev/null @@ -1,31 +0,0 @@ -// 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 -// 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.cloud.utils.db; - -/** - * JoinQueryBuilder builds queries for joins between multiple tables. - * - */ -public interface JoinQueryBuilder { - Select selectField(Object column); - - On innerJoin(Class entityClazz); - - J entity(Class entityClazz); - - FirstWhere where(); -} diff --git a/utils/src/com/cloud/utils/db/Merovingian.java b/utils/src/com/cloud/utils/db/Merovingian.java deleted file mode 100644 index 7e01b5ab76c..00000000000 --- a/utils/src/com/cloud/utils/db/Merovingian.java +++ /dev/null @@ -1,351 +0,0 @@ -// 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 -// 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.cloud.utils.db; - -import java.net.InetAddress; -import java.net.UnknownHostException; -import java.sql.Connection; -import java.sql.PreparedStatement; -import java.sql.ResultSet; -import java.sql.SQLException; -import java.sql.Savepoint; -import java.util.HashMap; -import java.util.HashSet; -import java.util.LinkedHashMap; -import java.util.Set; -import java.util.concurrent.TimeUnit; -import java.util.concurrent.locks.Lock; -import java.util.concurrent.locks.ReentrantLock; - -import org.apache.log4j.Logger; - -import com.cloud.utils.Pair; -import com.cloud.utils.Ternary; -import com.cloud.utils.exception.CloudRuntimeException; -import com.cloud.utils.net.MacAddress; -import com.cloud.utils.time.InaccurateClock; - -public class Merovingian { - private static final Logger s_logger = Logger.getLogger(Merovingian.class); - - private static final String ACQUIRE_SQL = "INSERT IGNORE INTO op_lock (op_lock.key, op_lock.mac, op_lock.ip, op_lock.thread) VALUES (?, ?, ?, ?)"; - private static final String INQUIRE_SQL = "SELECT op_lock.ip FROM op_lock WHERE op_lock.key = ?"; - private static final String RELEASE_SQL = "DELETE FROM op_lock WHERE op_lock.key = ?"; - private static final String CLEAR_SQL = "DELETE FROM op_lock WHERE op_lock.mac = ? AND op_lock.ip = ?"; - - private final static HashMap> s_memLocks = new HashMap>(1027); - - private final LinkedHashMap> _locks = new LinkedHashMap>(); - private int _previousIsolation = Connection.TRANSACTION_NONE; - - private final static String s_macAddress; - private final static String s_ipAddress; - static { - s_macAddress = MacAddress.getMacAddress().toString(":"); - String address = null; - try { - InetAddress addr = InetAddress.getLocalHost(); - address = addr.getHostAddress().toString(); - } catch (UnknownHostException e) { - address = "127.0.0.1"; - } - - s_ipAddress = address; - } - - Connection _conn = null; - - public Merovingian(short dbId) { - _conn = null; - } - - protected void checkIsolationLevel(Connection conn) throws SQLException { - PreparedStatement pstmt = conn.prepareStatement("SELECT @@global.tx_isolation, @@session.tx_isolation;"); - ResultSet rs = pstmt.executeQuery(); - while (rs.next()) { - s_logger.info("global isolation = " + rs.getString(1)); - s_logger.info("session isolation = " + rs.getString(2)); - } - } - - protected Connection getConnection(String key, boolean test) { - try { - if (_conn != null) { - return _conn; - } - - _conn = Transaction.getStandaloneConnection(); - if (_previousIsolation == Connection.TRANSACTION_NONE) { - _previousIsolation = _conn.getTransactionIsolation(); - _conn.setTransactionIsolation(Connection.TRANSACTION_READ_UNCOMMITTED); - if (!test && !_conn.getAutoCommit()) { - _conn.setAutoCommit(false); - } - } - return _conn; - } catch (SQLException e) { - try { - _conn.rollback(); - } catch (SQLException e1) { - } - throw new CloudRuntimeException("Unable to acquire db connection for locking " + key, e); - } - } - - public boolean acquire(String key, int timeInSeconds) { - Pair memLock = null; - boolean acquiredDbLock = false; - boolean acquiredMemLock = false; - try { - synchronized(s_memLocks) { - memLock = s_memLocks.get(key); - if (memLock == null) { - Lock l = new ReentrantLock(true); - memLock = new Pair(l, 0); - s_memLocks.put(key, memLock); - } - - memLock.second(memLock.second() + 1); - } - - if (!memLock.first().tryLock(timeInSeconds, TimeUnit.SECONDS)) { - return false; - } - acquiredMemLock = true; - - Ternary lock = _locks.get(key); - if (lock != null) { - lock.second(lock.second() + 1); - if (s_logger.isTraceEnabled()) { - s_logger.trace("Lock: Reacquiring " + key + " Count: " + lock.second()); - } - acquiredDbLock = true; - return true; - } - - long startTime = InaccurateClock.getTime(); - while ((InaccurateClock.getTime() - startTime) < (timeInSeconds * 1000)) { - if (isLocked(key)) { - try { - Thread.sleep(1000); - } catch (InterruptedException e) { - } - } else { - acquiredDbLock = doAcquire(key); - if (acquiredDbLock) { - return true; - } - } - } - if (s_logger.isTraceEnabled()) { - s_logger.trace("Lock: Timed out on acquiring lock " + key); - } - return false; - } catch (InterruptedException e) { - s_logger.debug("Interrupted while trying to acquire " + key); - return false; - } finally { - if (!acquiredMemLock || !acquiredDbLock) { - synchronized(s_memLocks) { - if (memLock.second(memLock.second() - 1) <= 0) { - s_memLocks.remove(key); - } - } - } - - if (acquiredMemLock && !acquiredDbLock) { - memLock.first().unlock(); - } - } - } - - protected boolean doAcquire(String key) { - Connection conn = getConnection(key, true); - PreparedStatement pstmt = null; - Savepoint sp = null; - try { - sp = conn.setSavepoint(key); - } catch (SQLException e) { - s_logger.warn("Unable to set save point " + key); - return false; - } - - try { - long startTime = InaccurateClock.getTime(); - try { - pstmt = conn.prepareStatement(ACQUIRE_SQL); - pstmt.setString(1, key); - pstmt.setString(2, s_macAddress); - pstmt.setString(3, s_ipAddress); - pstmt.setString(4, Thread.currentThread().getName()); - String exceptionMessage = null; - int rows = pstmt.executeUpdate(); - if (rows == 1) { - if (s_logger.isTraceEnabled()) { - s_logger.trace("Lock: lock acquired for " + key); - } - Ternary lock = new Ternary(sp, 1, InaccurateClock.getTime()); - _locks.put(key, lock); - return true; - } - } catch(SQLException e) { - s_logger.warn("Lock: Retrying lock " + key + ". Waited " + (InaccurateClock.getTime() - startTime), e); - } - - conn.rollback(sp); - s_logger.trace("Lock: Unable to acquire DB lock " + key); - } catch (SQLException e) { - s_logger.warn("Lock: Unable to acquire db connection for locking " + key, e); - } finally { - if (pstmt != null) { - try { - pstmt.close(); - } catch (SQLException e) { - } - } - } - return false; - } - - public boolean isLocked(String key) { - Connection conn = getConnection(key, false); - - PreparedStatement pstmt = null; - ResultSet rs = null; - try { - pstmt = conn.prepareStatement(INQUIRE_SQL); - pstmt.setString(1, key); - rs = pstmt.executeQuery(); - return rs.next(); - } catch (SQLException e) { - s_logger.warn("SQL exception " + e.getMessage(), e); - throw new CloudRuntimeException("SQL Exception on inquiry", e); - } finally { - try { - if (rs != null) { - rs.close(); - } - if (pstmt != null) { - pstmt.close(); - } - } catch (SQLException e) { - s_logger.warn("Unexpected SQL exception " + e.getMessage(), e); - } - } - } - - public void clear() { - if (_locks.size() == 0) { - return; - } - - Set keys = new HashSet(_locks.keySet()); - - // - // disable assertion, when assert support is enabled, it throws an exception - // which eventually eats the following on important messages for diagnostic - // - - // assert (false) : "Who acquired locks but didn't release them? " + keys.toArray(new String[keys.size()]); - - for (String key : keys) { - s_logger.warn("Lock: This is not good guys! Automatically releasing lock: " + key); - release(key); - } - - _locks.clear(); - } - - public boolean release(String key) { - boolean validLock = false; - try { - assert _locks.size() > 0 : "There are no locks here. Why are you trying to release " + key; - - Ternary lock = _locks.get(key); - if (lock != null) { - validLock = true; - - if (lock.second() > 1) { - lock.second(lock.second() - 1); - if (s_logger.isTraceEnabled()) { - s_logger.trace("Lock: Releasing " + key + " but not in DB " + lock.second()); - } - return false; - } - - - if (s_logger.isDebugEnabled() && !_locks.keySet().iterator().next().equals(key)) { - s_logger.trace("Lock: Releasing out of order for " + key); - } - _locks.remove(key); - if (s_logger.isTraceEnabled()) { - s_logger.trace("Lock: Releasing " + key + " after " + (InaccurateClock.getTime() - lock.third())); - } - Connection conn = getConnection(key, true); - - conn.rollback(lock.first()); - } else { - s_logger.warn("Merovingian.release() is called against key " + key + " but the lock of this key does not exist!"); - } - - if (_locks.size() == 0) { - closeConnection(); - } - - } catch (SQLException e) { - s_logger.warn("unable to rollback for " + key); - } finally { - synchronized(s_memLocks) { - Pair memLock = s_memLocks.get(key); - if(memLock != null) { - memLock.second(memLock.second() - 1); - if (memLock.second() <= 0) { - s_memLocks.remove(key); - } - - if(validLock) - memLock.first().unlock(); - } else { - throw new CloudRuntimeException("Merovingian.release() is called for key " + key + ", but its memory lock no longer exist! This is not good, guys"); - } - } - } - return true; - } - - public void closeConnection() { - try { - if (_conn == null) { - _previousIsolation = Connection.TRANSACTION_NONE; - return; - } - if (_previousIsolation != Connection.TRANSACTION_NONE) { - _conn.setTransactionIsolation(_previousIsolation); - } - try { // rollback just in case but really there shoul be nothing. - _conn.rollback(); - } catch (SQLException e) { - } - _conn.setAutoCommit(true); - _previousIsolation = Connection.TRANSACTION_NONE; - _conn.close(); - _conn = null; - } catch (SQLException e) { - s_logger.warn("Unexpected SQL exception " + e.getMessage(), e); - } - } -} diff --git a/utils/src/com/cloud/utils/db/NextWhere.java b/utils/src/com/cloud/utils/db/NextWhere.java deleted file mode 100644 index 0d65ae4e674..00000000000 --- a/utils/src/com/cloud/utils/db/NextWhere.java +++ /dev/null @@ -1,27 +0,0 @@ -// 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 -// 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.cloud.utils.db; - -public interface NextWhere extends FirstWhere { - NextWhere and(); - NextWhere or(); - NextWhere not(); - - @Override - void done(); - -} diff --git a/utils/src/com/cloud/utils/db/On.java b/utils/src/com/cloud/utils/db/On.java deleted file mode 100644 index 6965f4d5877..00000000000 --- a/utils/src/com/cloud/utils/db/On.java +++ /dev/null @@ -1,21 +0,0 @@ -// 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 -// 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.cloud.utils.db; - -public interface On { - -} diff --git a/utils/src/com/cloud/utils/db/ParentWhere.java b/utils/src/com/cloud/utils/db/ParentWhere.java deleted file mode 100644 index cc8278117da..00000000000 --- a/utils/src/com/cloud/utils/db/ParentWhere.java +++ /dev/null @@ -1,21 +0,0 @@ -// 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 -// 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.cloud.utils.db; - -public class ParentWhere { - -} diff --git a/utils/src/com/cloud/utils/db/QueryBuilder.java b/utils/src/com/cloud/utils/db/QueryBuilder.java deleted file mode 100644 index 2eb3658a20a..00000000000 --- a/utils/src/com/cloud/utils/db/QueryBuilder.java +++ /dev/null @@ -1,194 +0,0 @@ -// 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 -// 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.cloud.utils.db; - -import java.lang.reflect.Method; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; - -import net.sf.cglib.proxy.Enhancer; -import net.sf.cglib.proxy.MethodInterceptor; -import net.sf.cglib.proxy.MethodProxy; - -import com.cloud.utils.Pair; - -public class QueryBuilder implements MethodInterceptor, SimpleQueryBuilder, SelectQueryBuilder, JoinQueryBuilder { - public enum Func { - NATIVE("@", 1), - MAX("MAX(@)", 1), - MIN("MIN(@)", 1), - FIRST("FIRST(@)", 1), - LAST("LAST(@)", 1), - SUM("SUM(@)", 1), - COUNT("COUNT(@)", 1), - DISTINCT("DISTINCT(@)", 1); - - private String func; - private int count; - - Func(String func, int params) { - this.func = func; - this.count = params; - } - - @Override - public String toString() { - return func; - } - - public int getCount() { - return count; - } - } - - protected HashMap, Pair, Object>> _entities; - protected ArrayList _specifiedAttrs = new ArrayList(); - protected T _resultSetClass; - protected ArrayList> _selects; - - public QueryBuilder(Class resultSetClass, Class... clazzes) { - _entities = new HashMap, Pair, Object>>(clazzes.length); - for (Class clazz : clazzes) { - GenericDaoBase dao = GenericDaoBase.getDao(clazz); - Enhancer searchEnhancer = new Enhancer(); - searchEnhancer.setSuperclass(clazz); - searchEnhancer.setCallback(this); - Object entity = searchEnhancer.create(); - - _entities.put(clazz, new Pair, Object>(dao, entity)); - } - } - - protected void clean() { - _specifiedAttrs = null; - _entities = null; - } - - /** - * Constructor for SelectQueryBuilder interface. Must specify the - * table to be performing the query on and the result class to place it in. - * @param entityClass entity class to do the query on. - * @param resultSetClass result class to put the result set in. - */ - public QueryBuilder(Class entityClass, Class resultSetClass) { - _entities = new HashMap, Pair, Object>>(1); - GenericDaoBase dao = GenericDaoBase.getDao(entityClass); - Enhancer searchEnhancer = new Enhancer(); - searchEnhancer.setSuperclass(entityClass); - searchEnhancer.setCallback(this); - Object entity = searchEnhancer.create(); - - _entities.put(entityClass, new Pair, Object>(dao, entity)); - } - - @Override - public SimpleQueryBuilder selectFields(Object... fields) { - assert _entities != null && _entities.size() == 1 : "Now you've done it....Stop casting interfaces on the QueryBuilder"; - assert _specifiedAttrs.size() > 0 : "You didn't specify any attributes"; - - if (_selects == null) { - _selects = new ArrayList>(fields.length); - } - - for (Attribute attr : _specifiedAttrs) { - _selects.add(new Select(this, null, attr)); - } - - _specifiedAttrs.clear(); - - return this; - } - - protected void set(GenericDaoBase dao , String name) { - Attribute attr = dao.getAllAttributes().get(name); - assert (attr != null) : "Searching for a field that's not there: " + name; - _specifiedAttrs.add(attr); - } - - - @Override - public Object intercept(Object entity, Method method, Object[] args, MethodProxy proxy) throws Throwable { - Class entityClass = entity.getClass().getSuperclass(); - - Pair, Object> daoInfo = _entities.get(entityClass); - assert (daoInfo != null) : "You need to specify " + entityClass + " as one of the entities in the Query"; - GenericDaoBase dao = daoInfo.first(); - - String name = method.getName(); - if (name.startsWith("get")) { - String fieldName = Character.toLowerCase(name.charAt(3)) + name.substring(4); - set(dao, fieldName); - return null; - } else if (name.startsWith("is")) { - String fieldName = Character.toLowerCase(name.charAt(2)) + name.substring(3); - set(dao, fieldName); - return null; - } else { - assert false : "Perhaps you need to make the method start with get or is?"; - } - return proxy.invokeSuper(entity, args); - } - - @Override - @SuppressWarnings("unchecked") - public E entity(Class clazz) { - return (E)_entities.get(clazz).second(); - } - - @Override - @SuppressWarnings("unchecked") - public S entity() { - return (S)_entities.values().iterator().next().second(); - } - - @Override - public FirstWhere where() { - return new Where(this); - } - - @Override - public SimpleQueryBuilder selectAll() { - return this; - } - - public List getSpecifiedAttributes() { - return _specifiedAttrs; - } - - public Attribute getSpecifiedAttribute() { - assert _specifiedAttrs.size() == 1 : "You can only specify one attribute"; - return _specifiedAttrs.get(0); - } - - @Override - public Select selectColumn(Object column) { - return null; - } - - @Override - public Select selectField(Object column) { - // TODO Auto-generated method stub - return null; - } - - @Override - public On innerJoin(Class entityClazz) { - // TODO Auto-generated method stub - return null; - } -} diff --git a/utils/src/com/cloud/utils/db/SearchCriteria.java b/utils/src/com/cloud/utils/db/SearchCriteria.java index a0d944f08cd..aa1a223282e 100755 --- a/utils/src/com/cloud/utils/db/SearchCriteria.java +++ b/utils/src/com/cloud/utils/db/SearchCriteria.java @@ -53,24 +53,24 @@ public class SearchCriteria { AND(" AND ", 0), OR(" OR ", 0), NOT(" NOT ", 0); - + private final String op; int params; Op(String op, int params) { this.op = op; this.params = params; } - + @Override - public String toString() { + public String toString() { return op; } - + public int getParams() { return params; } } - + public enum Func { NATIVE("@", 1), MAX("MAX(@)", 1), @@ -80,25 +80,25 @@ public class SearchCriteria { SUM("SUM(@)", 1), COUNT("COUNT(@)", 1), DISTINCT("DISTINCT(@)", 1); - + private String func; private int count; - + Func(String func, int params) { this.func = func; this.count = params; } - + @Override public String toString() { return func; } - + public int getCount() { return count; } } - + public enum SelectType { Fields, Entity, @@ -117,46 +117,29 @@ public class SearchCriteria { private final List _groupByValues; private final Class _resultType; private final SelectType _selectType; - private final QueryBuilder _builder; - - protected SearchCriteria(QueryBuilder builder) { - _builder = builder; - _attrs = null; - _conditions = null; - _additionals = null; - _counter = 0; - _joins = null; - _selects = null; - _groupBy = null; - _groupByValues = null; - _resultType = null; - _selectType = null; - } - + protected SearchCriteria(final Map attrs, ArrayList conditions, ArrayList