Skip to content

Commit

Permalink
Fixes for secret-store initialization
Browse files Browse the repository at this point in the history
  • Loading branch information
jpkrohling committed Nov 5, 2015
1 parent e20f9da commit b062af9
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 72 deletions.

This file was deleted.

16 changes: 16 additions & 0 deletions secret-store-api/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,22 @@
<scope>provided</scope>
</dependency>

<dependency>
<groupId>org.jboss.logging</groupId>
<artifactId>jboss-logging</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.jboss.logging</groupId>
<artifactId>jboss-logging-annotations</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.jboss.logging</groupId>
<artifactId>jboss-logging-processor</artifactId>
<scope>provided</scope>
</dependency>

<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.hawkular.accounts.secretstore.control;
package org.hawkular.accounts.secretstore.api.internal;

import org.jboss.logging.Logger;
import org.jboss.logging.annotations.Cause;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,13 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.hawkular.accounts.secretstore.control;
package org.hawkular.accounts.secretstore.api.internal;

import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Future;
import java.util.stream.Collectors;

import javax.annotation.PostConstruct;
Expand All @@ -28,8 +30,11 @@
import javax.ejb.Startup;
import javax.enterprise.concurrent.ManagedExecutorService;
import javax.enterprise.context.ApplicationScoped;
import javax.enterprise.inject.Produces;
import javax.inject.Inject;

import org.hawkular.accounts.common.internal.CassandraSessionCallable;

import com.datastax.driver.core.Session;

/**
Expand All @@ -40,17 +45,25 @@
@ApplicationScoped
@PermitAll
public class SecretStoreSchemaInitializer {
private Future<Session> sessionFuture;

@Inject
CassandraSessionCallable cassandraSessionCallable;

MsgLogger logger = MsgLogger.LOGGER;

@Resource
private ManagedExecutorService executor;

@Inject
Session session;

@PostConstruct
public void init() {
executor.submit(() -> {
sessionFuture = executor.submit(cassandraSessionCallable);
}

@Produces @ApplicationScoped
public Session getSession() {
try {
Session session = sessionFuture.get();
InputStream input = getClass().getResourceAsStream("/secret-store.cql");
try (BufferedReader buffer = new BufferedReader(new InputStreamReader(input))) {
String content = buffer.lines().collect(Collectors.joining("\n"));
Expand All @@ -62,7 +75,9 @@ public void init() {
} catch (Exception e) {
logger.failedToInitializeSchema(e);
}
});

return session;
} catch (InterruptedException | ExecutionException e) {
throw new IllegalStateException("Could not get the initialized session.");
}
}
}
}

0 comments on commit b062af9

Please sign in to comment.