Search in sources :

Example 6 with KettleObjectExistsException

use of org.pentaho.di.core.exception.KettleObjectExistsException in project pentaho-kettle by pentaho.

the class KettleDatabaseRepositoryClusterSchemaDelegate method insertCluster.

private synchronized ObjectId insertCluster(ClusterSchema clusterSchema) throws KettleException {
    if (getClusterID(clusterSchema.getName()) != null) {
        // This cluster schema name is already in use. Throw an exception.
        throw new KettleObjectExistsException("Failed to create object in repository. Object [" + clusterSchema.getName() + "] already exists.");
    }
    ObjectId id = repository.connectionDelegate.getNextClusterID();
    RowMetaAndData table = new RowMetaAndData();
    table.addValue(new ValueMetaInteger(KettleDatabaseRepository.FIELD_CLUSTER_ID_CLUSTER), id);
    table.addValue(new ValueMetaString(KettleDatabaseRepository.FIELD_CLUSTER_NAME), clusterSchema.getName());
    table.addValue(new ValueMetaString(KettleDatabaseRepository.FIELD_CLUSTER_BASE_PORT), clusterSchema.getBasePort());
    table.addValue(new ValueMetaString(KettleDatabaseRepository.FIELD_CLUSTER_SOCKETS_BUFFER_SIZE), clusterSchema.getSocketsBufferSize());
    table.addValue(new ValueMetaString(KettleDatabaseRepository.FIELD_CLUSTER_SOCKETS_FLUSH_INTERVAL), clusterSchema.getSocketsFlushInterval());
    table.addValue(new ValueMetaBoolean(KettleDatabaseRepository.FIELD_CLUSTER_SOCKETS_COMPRESSED), Boolean.valueOf(clusterSchema.isSocketsCompressed()));
    table.addValue(new ValueMetaBoolean(KettleDatabaseRepository.FIELD_CLUSTER_DYNAMIC), Boolean.valueOf(clusterSchema.isDynamic()));
    repository.connectionDelegate.getDatabase().prepareInsert(table.getRowMeta(), KettleDatabaseRepository.TABLE_R_CLUSTER);
    repository.connectionDelegate.getDatabase().setValuesInsert(table);
    repository.connectionDelegate.getDatabase().insertRow();
    repository.connectionDelegate.getDatabase().closeInsert();
    return id;
}
Also used : ValueMetaString(org.pentaho.di.core.row.value.ValueMetaString) RowMetaAndData(org.pentaho.di.core.RowMetaAndData) ObjectId(org.pentaho.di.repository.ObjectId) KettleObjectExistsException(org.pentaho.di.core.exception.KettleObjectExistsException) ValueMetaInteger(org.pentaho.di.core.row.value.ValueMetaInteger) ValueMetaBoolean(org.pentaho.di.core.row.value.ValueMetaBoolean)

Example 7 with KettleObjectExistsException

use of org.pentaho.di.core.exception.KettleObjectExistsException in project pentaho-kettle by pentaho.

the class KettleDatabaseRepositorySlaveServerDelegate method saveSlaveServer.

public void saveSlaveServer(SlaveServer slaveServer, ObjectId id_transformation, boolean isUsedByTransformation, boolean overwrite) throws KettleException {
    if (slaveServer.getObjectId() == null) {
        // See if the slave doesn't exist already (just for safety and PDI-5102
        // 
        slaveServer.setObjectId(getSlaveID(slaveServer.getName()));
    }
    if (slaveServer.getObjectId() == null) {
        // New Slave Server
        slaveServer.setObjectId(insertSlave(slaveServer));
    } else {
        ObjectId existingSlaveId = slaveServer.getObjectId();
        if (existingSlaveId != null && slaveServer.getObjectId() != null && !slaveServer.getObjectId().equals(existingSlaveId)) {
            // A slave with this name already exists
            if (overwrite) {
                // Proceed with save, removing the original version from the repository first
                repository.deleteSlave(existingSlaveId);
                updateSlave(slaveServer);
            } else {
                throw new KettleObjectExistsException("Failed to save object to repository. Object [" + slaveServer.getName() + "] already exists.");
            }
        } else {
            // There are no naming collisions (either it is the same object or the name is unique)
            updateSlave(slaveServer);
        }
    }
    // Save the trans-slave relationship too.
    if (id_transformation != null && isUsedByTransformation) {
        repository.insertTransformationSlave(id_transformation, slaveServer.getObjectId());
    }
}
Also used : ObjectId(org.pentaho.di.repository.ObjectId) KettleObjectExistsException(org.pentaho.di.core.exception.KettleObjectExistsException)

Example 8 with KettleObjectExistsException

use of org.pentaho.di.core.exception.KettleObjectExistsException in project pentaho-kettle by pentaho.

the class SharedDatabaseUtil method addSharedDatabase.

/**
 * Add a database to the list of shared databases in ~/.kettle/shared.xml
 *
 * @param databaseMeta
 * @throws KettleException in case there is an error
 * @throws KettleObjectExistsException if a database with the same name already exists
 */
public static void addSharedDatabase(DatabaseMeta databaseMeta) throws KettleObjectExistsException, KettleException {
    // First verify existence...
    // 
    List<DatabaseMeta> sharedDatabases = loadSharedDatabases();
    DatabaseMeta found = DatabaseMeta.findDatabase(sharedDatabases, databaseMeta.getName());
    if (found != null) {
        throw new KettleObjectExistsException("A database with name '" + databaseMeta.getName() + "' already exists in the shared databases list.");
    }
    try {
        SharedObjects sharedObjects = new SharedObjects();
        sharedObjects.storeObject(databaseMeta);
        sharedObjects.saveToFile();
    } catch (Exception e) {
        throw new KettleException("It was not possible to add database '" + databaseMeta.getName() + "' to the shared.xml file");
    }
}
Also used : KettleException(org.pentaho.di.core.exception.KettleException) KettleObjectExistsException(org.pentaho.di.core.exception.KettleObjectExistsException) SharedObjects(org.pentaho.di.shared.SharedObjects) DatabaseMeta(org.pentaho.di.core.database.DatabaseMeta) KettleException(org.pentaho.di.core.exception.KettleException) KettleObjectExistsException(org.pentaho.di.core.exception.KettleObjectExistsException)

Aggregations

KettleObjectExistsException (org.pentaho.di.core.exception.KettleObjectExistsException)8 ObjectId (org.pentaho.di.repository.ObjectId)7 RowMetaAndData (org.pentaho.di.core.RowMetaAndData)3 ValueMetaBoolean (org.pentaho.di.core.row.value.ValueMetaBoolean)3 ValueMetaInteger (org.pentaho.di.core.row.value.ValueMetaInteger)3 ValueMetaString (org.pentaho.di.core.row.value.ValueMetaString)3 SlaveServer (org.pentaho.di.cluster.SlaveServer)1 DatabaseMeta (org.pentaho.di.core.database.DatabaseMeta)1 KettleException (org.pentaho.di.core.exception.KettleException)1 KettleJobException (org.pentaho.di.core.exception.KettleJobException)1 KettleTransException (org.pentaho.di.core.exception.KettleTransException)1 RepositoryDirectoryInterface (org.pentaho.di.repository.RepositoryDirectoryInterface)1 RepositoryExtended (org.pentaho.di.repository.RepositoryExtended)1 SharedObjects (org.pentaho.di.shared.SharedObjects)1