Permalink
Browse files

Reporting and general upgrade changes for 3.2 (EUCA-3828)

Reporting upgrade is updated to use the new upgrade mechanism. Three
new classes are added for handling reporting upgrade to 3.2. The
PreUpgrade32 class removes reporting tables that are no longer used.
The Upgrade32 class runs for reporting user and account entities and
removes the existing data (which will be missing some columns). The
PostUpgrade32 class populates reporting data in the new format for any
items that exist in the cloud. The UpgradeUtils class provides
supporting methods for reporting upgrades.

Upgrade scripts and support classes related to the old upgrade mechanism
are removed. The StandalonePersistence class is preserved as it can be
used when running test code (it is no longer required for upgrade)
  • Loading branch information...
1 parent cbf4ab9 commit d5c7d3e5cbdc886cc8a65be3a6b7dd7d24ae9c98 @sjones4 sjones4 committed Oct 24, 2012
@@ -1,61 +0,0 @@
-import com.eucalyptus.upgrade.AbstractUpgradeScript
-import com.eucalyptus.entities.PersistenceContexts
-import com.eucalyptus.reporting.domain.ReportingUser
-import javax.persistence.EntityManagerFactory
-import com.eucalyptus.system.Ats
-import javax.persistence.PersistenceContext
-import javax.persistence.EntityManager
-import javax.persistence.EntityTransaction
-import com.eucalyptus.reporting.domain.ReportingAccount
-import com.eucalyptus.reporting.ReportingDataVerifier
-
-class upgrade_31_32 extends AbstractUpgradeScript {
-
- upgrade_31_32() {
- super(1, ["3.1.0", "3.1.1", "3.1.2"], ["3.2.0"])
- }
-
- @Override
- void upgrade( final File oldEucaHome,
- final File newEucaHome ) {
- upgradeReporting()
- }
-
- private void transactionalForContext( final Object exampleEntity, final Closure callback ) {
- String context = Ats.inClassHierarchy( exampleEntity ).get( PersistenceContext.class ).name()
- EntityManagerFactory entityManagerFactory = PersistenceContexts.getEntityManagerFactory( context );
- EntityManager entityManager = entityManagerFactory.createEntityManager( );
- EntityTransaction transaction = entityManager.getTransaction( );
- transaction.begin()
- boolean success = false
- try {
- callback.call( entityManager )
- success = true
- } finally {
- if ( success && !transaction.rollbackOnly ) {
- transaction.commit()
- } else {
- transaction.rollback()
- }
- }
- }
-
- private void upgradeReporting() {
- transactionalForContext( ReportingUser.class ) {
- EntityManager entityManager ->
- // delete old tables
- [ 'storage_usage_snapshot', 'instance_usage_snapshot', 's3_usage_snapshot', 'reporting_instance' ].each { table ->
- entityManager.createNativeQuery( 'drop table if exists ' + table ).executeUpdate()
- }
-
- // purge old data from re-used tables
- [ ReportingUser.class, ReportingAccount.class ].each { entityClass ->
- entityManager.createQuery( 'delete from ' + entityClass.getName() ).executeUpdate()
- }
-
- // create events for existing entities
- String desc = ReportingDataVerifier.addMissingReportingEvents()
- LOG.info( "Reporting event status / changes:\n " + desc )
- }
- }
-}
@@ -1,109 +0,0 @@
-/*************************************************************************
- * Copyright 2009-2012 Eucalyptus Systems, Inc.
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; version 3 of the License.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see http://www.gnu.org/licenses/.
- *
- * Please contact Eucalyptus Systems, Inc., 6755 Hollister Ave., Goleta
- * CA 93117, USA or visit http://www.eucalyptus.com/licenses/ if you need
- * additional information or have any questions.
- *
- * This file may incorporate work covered under the following copyright
- * and permission notice:
- *
- * Software License Agreement (BSD License)
- *
- * Copyright (c) 2008, Regents of the University of California
- * All rights reserved.
- *
- * Redistribution and use of this software in source and binary forms,
- * with or without modification, are permitted provided that the
- * following conditions are met:
- *
- * Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- *
- * Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer
- * in the documentation and/or other materials provided with the
- * distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
- * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
- * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
- * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
- * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
- * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
- * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGE. USERS OF THIS SOFTWARE ACKNOWLEDGE
- * THE POSSIBLE PRESENCE OF OTHER OPEN SOURCE LICENSED MATERIAL,
- * COPYRIGHTED MATERIAL OR PATENTED MATERIAL IN THIS SOFTWARE,
- * AND IF ANY SUCH MATERIAL IS DISCOVERED THE PARTY DISCOVERING
- * IT MAY INFORM DR. RICH WOLSKI AT THE UNIVERSITY OF CALIFORNIA,
- * SANTA BARBARA WHO WILL THEN ASCERTAIN THE MOST APPROPRIATE REMEDY,
- * WHICH IN THE REGENTS' DISCRETION MAY INCLUDE, WITHOUT LIMITATION,
- * REPLACEMENT OF THE CODE SO IDENTIFIED, LICENSING OF THE CODE SO
- * IDENTIFIED, OR WITHDRAWAL OF THE CODE CAPABILITY TO THE EXTENT
- * NEEDED TO COMPLY WITH ANY SUCH LICENSES OR RIGHTS.
- ************************************************************************/
-
-package com.eucalyptus.upgrade;
-
-import java.util.List;
-import org.apache.log4j.Logger;
-
-/**
- * Any Class implementing this interface will be registered as a candidate for usage during the upgrade procedure.
- */
-public abstract class AbstractUpgradeScript implements UpgradeScript {
- protected final int priority;
- protected final List<String> versionFrom;
- protected final List<String> versionTo;
- protected Logger LOG = Logger.getLogger( getClass() );
-
- protected AbstractUpgradeScript( final int priority,
- final List<String> versionFrom,
- final List<String> versionTo ) {
- this.priority = priority;
- this.versionFrom = versionFrom;
- this.versionTo = versionTo;
- }
-
- @Override
- public Boolean accepts( final String from, final String to ) {
- return versionFrom.contains(from) && versionTo.contains(to);
- }
-
- @Override
- public int getPriority() {
- return priority;
- }
-
- @Override
- public void setLogger( final Logger log ) {
- LOG = log;
- }
-
- @Override
- public int compareTo(UpgradeScript o) {
- if(o.getPriority() == priority)
- return 0 ;
- if(o.getPriority() < priority)
- return 1;
- else
- return -1;
- }
-}
@@ -1,72 +0,0 @@
-/*************************************************************************
- * Copyright 2009-2012 Eucalyptus Systems, Inc.
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; version 3 of the License.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see http://www.gnu.org/licenses/.
- *
- * Please contact Eucalyptus Systems, Inc., 6755 Hollister Ave., Goleta
- * CA 93117, USA or visit http://www.eucalyptus.com/licenses/ if you need
- * additional information or have any questions.
- *
- * This file may incorporate work covered under the following copyright
- * and permission notice:
- *
- * Software License Agreement (BSD License)
- *
- * Copyright (c) 2008, Regents of the University of California
- * All rights reserved.
- *
- * Redistribution and use of this software in source and binary forms,
- * with or without modification, are permitted provided that the
- * following conditions are met:
- *
- * Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- *
- * Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer
- * in the documentation and/or other materials provided with the
- * distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
- * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
- * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
- * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
- * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
- * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
- * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGE. USERS OF THIS SOFTWARE ACKNOWLEDGE
- * THE POSSIBLE PRESENCE OF OTHER OPEN SOURCE LICENSED MATERIAL,
- * COPYRIGHTED MATERIAL OR PATENTED MATERIAL IN THIS SOFTWARE,
- * AND IF ANY SUCH MATERIAL IS DISCOVERED THE PARTY DISCOVERING
- * IT MAY INFORM DR. RICH WOLSKI AT THE UNIVERSITY OF CALIFORNIA,
- * SANTA BARBARA WHO WILL THEN ASCERTAIN THE MOST APPROPRIATE REMEDY,
- * WHICH IN THE REGENTS' DISCRETION MAY INCLUDE, WITHOUT LIMITATION,
- * REPLACEMENT OF THE CODE SO IDENTIFIED, LICENSING OF THE CODE SO
- * IDENTIFIED, OR WITHDRAWAL OF THE CODE CAPABILITY TO THE EXTENT
- * NEEDED TO COMPLY WITH ANY SUCH LICENSES OR RIGHTS.
- ************************************************************************/
-
-package com.eucalyptus.upgrade;
-
-import groovy.sql.Sql;
-import java.sql.SQLException;
-
-public interface DatabaseSource {
-
- public abstract Sql getSqlSession( String persistenceContext ) throws SQLException;
-
-}
@@ -1,120 +0,0 @@
-/*************************************************************************
- * Copyright 2009-2012 Eucalyptus Systems, Inc.
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; version 3 of the License.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see http://www.gnu.org/licenses/.
- *
- * Please contact Eucalyptus Systems, Inc., 6755 Hollister Ave., Goleta
- * CA 93117, USA or visit http://www.eucalyptus.com/licenses/ if you need
- * additional information or have any questions.
- *
- * This file may incorporate work covered under the following copyright
- * and permission notice:
- *
- * Software License Agreement (BSD License)
- *
- * Copyright (c) 2008, Regents of the University of California
- * All rights reserved.
- *
- * Redistribution and use of this software in source and binary forms,
- * with or without modification, are permitted provided that the
- * following conditions are met:
- *
- * Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- *
- * Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer
- * in the documentation and/or other materials provided with the
- * distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
- * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
- * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
- * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
- * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
- * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
- * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGE. USERS OF THIS SOFTWARE ACKNOWLEDGE
- * THE POSSIBLE PRESENCE OF OTHER OPEN SOURCE LICENSED MATERIAL,
- * COPYRIGHTED MATERIAL OR PATENTED MATERIAL IN THIS SOFTWARE,
- * AND IF ANY SUCH MATERIAL IS DISCOVERED THE PARTY DISCOVERING
- * IT MAY INFORM DR. RICH WOLSKI AT THE UNIVERSITY OF CALIFORNIA,
- * SANTA BARBARA WHO WILL THEN ASCERTAIN THE MOST APPROPRIATE REMEDY,
- * WHICH IN THE REGENTS' DISCRETION MAY INCLUDE, WITHOUT LIMITATION,
- * REPLACEMENT OF THE CODE SO IDENTIFIED, LICENSING OF THE CODE SO
- * IDENTIFIED, OR WITHDRAWAL OF THE CODE CAPABILITY TO THE EXTENT
- * NEEDED TO COMPLY WITH ANY SUCH LICENSES OR RIGHTS.
- ************************************************************************/
-
-package com.eucalyptus.upgrade;
-
-import groovy.sql.Sql;
-import java.io.File;
-import java.io.IOException;
-import java.sql.Connection;
-import java.sql.Driver;
-import java.sql.DriverManager;
-import java.sql.SQLException;
-import java.util.Properties;
-import org.apache.log4j.Logger;
-import com.eucalyptus.bootstrap.SystemIds;
-import com.eucalyptus.crypto.Hmacs;
-
-public class HsqldbSource implements DatabaseSource {
- private static Logger LOG = Logger.getLogger( HsqldbSource.class );
- private File oldDbDir = new File( System.getProperty( "euca.upgrade.old.dir" ) + "/var/lib/eucalyptus/db/" );
- private static Driver driver;
- private static Properties props;
- static {
- try {
- Class driverClass = ClassLoader.getSystemClassLoader( ).loadClass( "org.hsqldb.jdbcDriver" );
- driver = ( Driver ) driverClass.newInstance( );
- } catch ( Exception e ) {
- LOG.debug( e, e );
- System.exit( -1 );
- }
- }
-
- public HsqldbSource( ) {}
-
- /**
- * @see com.eucalyptus.upgrade.DatabaseSource#getSqlSession(java.lang.String)
- * @param persistenceContext
- * @return
- * @throws SQLException
- */
- public Sql getSqlSession( String persistenceContext ) throws SQLException {
- String url = "jdbc:hsqldb:file:" + oldDbDir.getAbsolutePath( ) + File.separator + persistenceContext;
- if ( props == null ) {
- synchronized ( HsqldbSource.class ) {
- if ( props == null ) {
- props = new Properties( );
- props.setProperty( "user", "sa" );
- props.setProperty( "password", SystemIds.databasePassword( ) );
- // NB: readonly is HSQLDB-specific
- props.setProperty( "readonly", "true" );
- }
- }
- }
- try {
- Connection conn = driver.connect( url, props );
- return new Sql( conn );
- } catch ( SQLException e) {
- return null;
- }
- }
-}
Oops, something went wrong.

0 comments on commit d5c7d3e

Please sign in to comment.