Search in sources :

Example 1 with ProfileRegistry

use of io.fabric8.api.ProfileRegistry in project fabric8 by jboss-fuse.

the class AbstractChildContainerCreateAction method getDataStoreProperties.

protected Map<String, String> getDataStoreProperties() {
    ProfileRegistry profileRegistry = fabricService.adapt(ProfileRegistry.class);
    Map<String, String> options = new HashMap<String, String>(profileRegistry.getDataStoreProperties());
    if (dataStoreOption != null) {
        for (String opt : dataStoreOption) {
            String[] parts = opt.trim().split(" +");
            options.put(parts[0], parts[1]);
        }
    }
    return options;
}
Also used : HashMap(java.util.HashMap) ProfileRegistry(io.fabric8.api.ProfileRegistry)

Example 2 with ProfileRegistry

use of io.fabric8.api.ProfileRegistry in project fabric8 by jboss-fuse.

the class ProjectDeployerImpl method writeRequirementsJson.

private ProjectRequirements writeRequirementsJson(ProjectRequirements requirements, Profile profile, ProfileBuilder builder) throws IOException {
    ObjectMapper mapper = DtoHelper.getMapper();
    byte[] json = mapper.writeValueAsBytes(requirements);
    String fileName = DtoHelper.getRequirementsConfigFileName(requirements);
    // lets read the previous requirements if there are any
    ProfileRegistry profileRegistry = fabricService.get().adapt(ProfileRegistry.class);
    byte[] oldData = profile.getFileConfiguration(fileName);
    LOG.info("Writing file " + fileName + " to profile " + profile);
    builder.addFileConfiguration(fileName, json);
    if (oldData == null || oldData.length == 0) {
        return null;
    } else {
        return mapper.reader(ProjectRequirements.class).readValue(oldData);
    }
}
Also used : ProfileRegistry(io.fabric8.api.ProfileRegistry) ProjectRequirements(io.fabric8.deployer.dto.ProjectRequirements) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Example 3 with ProfileRegistry

use of io.fabric8.api.ProfileRegistry in project fabric8 by jboss-fuse.

the class ProvisionSupport method profileAvailable.

public static Boolean profileAvailable(String profile, String version, Long timeout) throws Exception {
    FabricService fabricService = ServiceLocator.awaitService(FabricService.class);
    ProfileRegistry profileRegistry = fabricService.adapt(ProfileRegistry.class);
    for (long t = 0; (!profileRegistry.hasProfile(version, profile) && t < timeout); t += 2000L) {
        Thread.sleep(2000L);
    }
    return profileRegistry.hasProfile(version, profile);
}
Also used : FabricService(io.fabric8.api.FabricService) ProfileRegistry(io.fabric8.api.ProfileRegistry)

Example 4 with ProfileRegistry

use of io.fabric8.api.ProfileRegistry in project fabric8 by jboss-fuse.

the class GitDataStoreImplProfilesIT method init.

@Before
public void init() throws NoSuchFieldException, IllegalAccessException, IOException, GitAPIException {
    File repo = new File("target/fabric-git");
    FileUtils.deleteDirectory(repo);
    repo.mkdirs();
    git = Git.init().setDirectory(repo).setGitDir(new File(repo, ".git")).call();
    git.commit().setMessage("init").call();
    git.tag().setName(GitHelpers.ROOT_TAG).call();
    dataStore = mock(DataStore.class);
    when(dataStore.getDefaultVersion()).thenReturn("1.0");
    gitService = mock(GitService.class);
    when(gitService.getGit()).thenReturn(git);
    runtimeProperties = mock(RuntimeProperties.class);
    when(runtimeProperties.getRuntimeIdentity()).thenReturn("root");
    curator = mock(CuratorFramework.class);
    pullPushPolicy = mock(PullPushPolicy.class);
    PullPushPolicy.PushPolicyResult ppResult = mock(PullPushPolicy.PushPolicyResult.class);
    when(ppResult.getPushResults()).thenReturn(new ArrayList<PushResult>());
    when(pullPushPolicy.doPush(any(GitContext.class), any(CredentialsProvider.class))).thenReturn(ppResult);
    mockStatic(ZooKeeperUtils.class);
    PowerMockito.when(ZooKeeperUtils.generateContainerToken(runtimeProperties, curator)).thenReturn("token");
    gdsi = new GitDataStoreImpl();
    this.<ValidationSupport>getField(gdsi, "active", ValidationSupport.class).setValid();
    this.<ValidatingReference<DataStore>>getField(gdsi, "dataStore", ValidatingReference.class).bind(dataStore);
    this.<ValidatingReference<GitService>>getField(gdsi, "gitService", ValidatingReference.class).bind(gitService);
    this.<ValidatingReference<RuntimeProperties>>getField(gdsi, "runtimeProperties", ValidatingReference.class).bind(runtimeProperties);
    this.<ValidatingReference<CuratorFramework>>getField(gdsi, "curator", ValidatingReference.class).bind(curator);
    setField(gdsi, "dataStoreProperties", Map.class, new HashMap<String, Object>());
    setField(gdsi, "pullPushPolicy", PullPushPolicy.class, pullPushPolicy);
    profileRegistry = gdsi;
}
Also used : ValidatingReference(io.fabric8.api.scr.ValidatingReference) ValidationSupport(io.fabric8.api.scr.ValidationSupport) PullPushPolicy(io.fabric8.git.PullPushPolicy) PushResult(org.eclipse.jgit.transport.PushResult) CredentialsProvider(org.eclipse.jgit.transport.CredentialsProvider) CuratorFramework(org.apache.curator.framework.CuratorFramework) GitContext(io.fabric8.api.GitContext) DataStore(io.fabric8.api.DataStore) GitService(io.fabric8.git.GitService) File(java.io.File) RuntimeProperties(io.fabric8.api.RuntimeProperties) Before(org.junit.Before)

Example 5 with ProfileRegistry

use of io.fabric8.api.ProfileRegistry in project fabric8 by jboss-fuse.

the class ProfileDynamicJaxbCompiler method listFiles.

private Collection<String> listFiles(final String versionId, final Iterable<String> profileIds, final String path) {
    assertValid();
    Git git = gitService.getGit();
    ProfileRegistry profileRegistry = getFabricService().adapt(ProfileRegistry.class);
    SortedSet<String> answer = new TreeSet<String>();
    for (String profileId : profileIds) {
        profileRegistry.getRequiredProfile(versionId, profileId);
        File profileDirectory = GitHelpers.getProfileDirectory(git, profileId);
        File file = Strings.isNotBlank(path) ? new File(profileDirectory, path) : profileDirectory;
        if (file.exists()) {
            String[] values = file.list();
            if (values != null) {
                for (String value : values) {
                    answer.add(value);
                }
            }
        }
    }
    return Collections.unmodifiableSet(answer);
}
Also used : Git(org.eclipse.jgit.api.Git) TreeSet(java.util.TreeSet) ProfileRegistry(io.fabric8.api.ProfileRegistry) File(java.io.File)

Aggregations

ProfileRegistry (io.fabric8.api.ProfileRegistry)8 File (java.io.File)3 FabricService (io.fabric8.api.FabricService)2 GitContext (io.fabric8.api.GitContext)2 Version (io.fabric8.api.Version)2 HashMap (java.util.HashMap)2 CuratorFramework (org.apache.curator.framework.CuratorFramework)2 Git (org.eclipse.jgit.api.Git)2 PushResult (org.eclipse.jgit.transport.PushResult)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 DataStore (io.fabric8.api.DataStore)1 FabricException (io.fabric8.api.FabricException)1 LockHandle (io.fabric8.api.LockHandle)1 Profile (io.fabric8.api.Profile)1 ProfileBuilder (io.fabric8.api.ProfileBuilder)1 ProfileService (io.fabric8.api.ProfileService)1 RuntimeProperties (io.fabric8.api.RuntimeProperties)1 VersionBuilder (io.fabric8.api.VersionBuilder)1 ValidatingReference (io.fabric8.api.scr.ValidatingReference)1 ValidationSupport (io.fabric8.api.scr.ValidationSupport)1